Hi Vedavyas,
You can automate certificate management with Ansible and AD CS, but the best approach depends on whether your target servers are domain-joined and what type of certificates you're managing.
If you're working with domain-joined Windows servers, I would recommend using AD CS auto-enrollment for certificate issuance and renewal, and Ansible for certificate validation, installation, and application-specific configuration.
Here is how I would approach it:
1. Configure AD CS and certificate auto-enrollment
First, confirm that the required certificate template is published on your Enterprise CA. The computer accounts requesting certificates should have Read, Enroll, and Autoenroll permissions on that template.
Then configure auto-enrollment through Group Policy:
Computer Configuration > Policies > Windows Settings > Security Settings > Public Key Policies > Certificate Services Client - Auto-Enrollment
Enable the policy and select both renewal and certificate template update options.
On a test server, you can run gpupdate /force followed by certutil -pulse to trigger auto-enrollment and verify that the certificate is issued correctly.
Microsoft has a useful guide here:
Configure certificate auto-enrollment
2. Use Ansible for certificate management
The ansible.windows collection provides modules that can help:
· win_certificate_info – Check installed certificates, expiration dates, thumbprints, and other certificate details.
· win_certificate_store – Import, export, or remove certificates from Windows certificate stores.
· win_powershell – Run PowerShell commands for enrollment or other certificate-related tasks.
For example, you could create a playbook that checks certificate expiration dates, identifies certificates nearing expiry, and performs the required actions based on your renewal process.
3. Handle custom CSR generation and renewal
If you need Ansible to generate CSRs with specific subject names or SAN entries, you can execute Windows certreq commands through Ansible.
The typical workflow is:
· certreq -new to generate the CSR.
· certreq -submit to submit the request to AD CS.
· certreq -accept to install the issued certificate.
For machine certificates, make sure the request is generated in the correct machine context and the INF configuration includes MachineKeySet = TRUE.
You can also use PowerShell's Get-Certificate cmdlet for template-based enrollment. Be aware that enrollment through WinRM may require additional authentication or delegation configuration.
Microsoft documents the CSR process here:
Request and renew AD CS certificates
4. Validate and apply the renewed certificate
Once a certificate is issued or renewed, have Ansible verify its expiration, subject/SAN, intended usage, and private-key association. If the certificate is used by IIS or another application, you may also need to update its certificate binding so the service starts using the new certificate.
To help you with a working playbook, could you clarify a few things?
1. Are you managing certificates for domain-joined Windows servers, or do you also have standalone servers?
2. Which certificates are you trying to automate (IIS SSL, LDAPS, RDP, or something else)?
3. Is AD CS already configured with certificate templates, and do you want fully automatic renewal or a workflow involving approval?
4. Which Windows Server and Ansible versions are you using, and are you connecting to the servers through WinRM?
With these details, we can narrow down the approach and put together an Ansible playbook for CSR generation, renewal, and certificate installation that fits your environment.