Skip to content

Instantly share code, notes, and snippets.

@frasertweedale
Created May 13, 2020 03:37
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frasertweedale/ca42ff31d5f5b8d3c6d4d3a94f9fbd0e to your computer and use it in GitHub Desktop.
Save frasertweedale/ca42ff31d5f5b8d3c6d4d3a94f9fbd0e to your computer and use it in GitHub Desktop.
certbot-dns-ipa.py
#!/usr/bin/python3
import os
from dns import resolver
from ipalib import api
from ipapython import dnsutil
certbot_domain = os.environ['CERTBOT_DOMAIN']
certbot_validation = os.environ['CERTBOT_VALIDATION']
if 'CERTBOT_AUTH_OUTPUT' in os.environ:
command = 'dnsrecord_del'
else:
command = 'dnsrecord_add'
validation_domain = f'_acme-challenge.{certbot_domain}'
fqdn = dnsutil.DNSName(validation_domain).make_absolute()
zone = dnsutil.DNSName(resolver.zone_for_name(fqdn))
name = fqdn.relativize(zone)
api.bootstrap(context='cli')
api.finalize()
api.Backend.rpcclient.connect()
api.Command[command](zone, name, txtrecord=[certbot_validation], dnsttl=60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment