'Generate the certificate signing request.'

def generate(self, module):

    if ((not self.check(module, perms_required=False)) or self.force):
        req = crypto.X509Req()
        req.set_version(self.version)
        subject = req.get_subject()
        for (key, value) in self.subject.items():
            if (value is not None):
                setattr(subject, key, value)
        altnames = ',    '.join(self.subjectAltName)
        extensions = [crypto.X509Extension('subjectAltName', False, altnames.encode('ascii'))]
        if self.keyUsage:
            usages = ',    '.join(self.keyUsage)
            extensions.append(crypto.X509Extension('keyUsage', False, usages.encode('ascii')))
        if self.extendedKeyUsage:
            usages = ',    '.join(self.extendedKeyUsage)
            extensions.append(crypto.X509Extension('extendedKeyUsage', False, usages.encode('ascii')))
        req.add_extensions(extensions)
        req.set_pubkey(self.privatekey)
        req.sign(self.privatekey, self.digest)
        self.request = req
        try:
            csr_file = open(self.path, 'wb')
            csr_file.write(crypto.dump_certificate_request(crypto.FILETYPE_PEM, self.request))
            csr_file.close()
        except (IOError, OSError) as exc:
            raise CertificateSigningRequestError(exc)
        self.changed = True
    file_args = module.load_file_common_arguments(module.params)
    if module.set_fs_attributes_if_different(file_args, False):
        self.changed = True
