# Buggy code
def _copy_create_ssl_vhost_skeleton(self, vhost, ssl_fp):
    """Copies over existing Vhost with IfModule mod_ssl.c> skeleton.

    :param obj.VirtualHost vhost: Original VirtualHost object
    :param str ssl_fp: Full path where the new ssl_vhost will reside.

    A new file is created on the filesystem.

    """
    # First register the creation so that it is properly removed if
    # configuration is rolled back
    if os.path.exists(ssl_fp):
        notes = "Appended new VirtualHost directive to file %s" % ssl_fp
        files = set()
        files.add(ssl_fp)
        self.reverter.add_to_checkpoint(files, notes)
    else:
        self.reverter.register_file_creation(False, ssl_fp)
    sift = False

    try:
        orig_contents = self._get_vhost_block(vhost)
        ssl_vh_contents, sift = self._sift_rewrite_rules(orig_contents)

        with open(ssl_fp, "a") as new_file:
            new_file.write("<IfModule mod_ssl.c>\n")
            new_file.write("\n".join(ssl_vh_contents))
            # The content does not include the closing tag, so add it
            new_file.write("</VirtualHost>\n")
            new_file.write("</IfModule>\n")
    except IOError:
        logger.fatal("Error writing/reading to file in make_vhost_ssl")
        raise errors.PluginError("Unable to write/read in make_vhost_ssl")

    if sift:
        reporter = zope.component.getUtility(interfaces.IReporter)
        reporter.add_message(
            "Some rewrite rules copied from {0} were disabled in the "
            "vhost for your HTTPS site located at {1} because they have "
            "the potential to create redirection loops.".format(vhost.filep, ssl_fp),
            reporter.MEDIUM_PRIORITY,
        )
    self.aug.set("/augeas/files%s/mtime" % (self._escape(ssl_fp)), "0")
    self.aug.set("/augeas/files%s/mtime" % (self._escape(vhost.filep)), "0")


# 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 _copy_create_ssl_vhost_skeleton(self, vhost, ssl_fp):
    """Copies over existing Vhost with IfModule mod_ssl.c> skeleton.

    :param obj.VirtualHost vhost: Original VirtualHost object
    :param str ssl_fp: Full path where the new ssl_vhost will reside.

    A new file is created on the filesystem.

    """
    # First register the creation so that it is properly removed if
    # configuration is rolled back
    if os.path.exists(ssl_fp):
        notes = "Appended new VirtualHost directive to file %s" % ssl_fp
        files = set()
        files.add(ssl_fp)
        self.reverter.add_to_checkpoint(files, notes)
    else:
        self.reverter.register_file_creation(False, ssl_fp)
    sift = False

    try:
        orig_contents = self._get_vhost_block(vhost)
        ssl_vh_contents, sift = self._sift_rewrite_rules(orig_contents)

        with open(ssl_fp, "a") as new_file:
            new_file.write("<IfModule mod_ssl.c>\n")
            new_file.write("\n".join(ssl_vh_contents))
            # The content does not include the closing tag, so add it
            new_file.write("</VirtualHost>\n")
            new_file.write("</IfModule>\n")
        # Add new file to augeas paths if we're supposed to handle
        # activation (it's not included as default)
        if not self.parser.parsed_in_current(ssl_fp):
            self.parser.parse_file(ssl_fp)
    except IOError:
        logger.fatal("Error writing/reading to file in make_vhost_ssl")
        raise errors.PluginError("Unable to write/read in make_vhost_ssl")

    if sift:
        reporter = zope.component.getUtility(interfaces.IReporter)
        reporter.add_message(
            "Some rewrite rules copied from {0} were disabled in the "
            "vhost for your HTTPS site located at {1} because they have "
            "the potential to create redirection loops.".format(vhost.filep, ssl_fp),
            reporter.MEDIUM_PRIORITY,
        )
    self.aug.set("/augeas/files%s/mtime" % (self._escape(ssl_fp)), "0")
    self.aug.set("/augeas/files%s/mtime" % (self._escape(vhost.filep)), "0")