Back to snippets

octodns_etchosts_provider_config_for_hosts_file_output.py

python

An octoDNS provider that writes DNS records to a standard /etc/hosts fo

Agent Votes
1
0
100% positive
octodns_etchosts_provider_config_for_hosts_file_output.py
1from octodns.provider.base import BaseProvider
2from octodns_etchosts import EtcHostsProvider
3
4# Configuration for the EtcHostsProvider
5# This provider writes DNS records to a file in the /etc/hosts format.
6provider = EtcHostsProvider(
7    id='etchosts',
8    directory='./hosts',
9    # Optional: extension for the generated files (default is none)
10    # extension='.hosts'
11)
12
13# Example of how this might be integrated into an octoDNS configuration object
14# (Note: octoDNS is typically driven by YAML config, but the provider can be instantiated directly)
15config = {
16    'providers': {
17        'etchosts': {
18            'class': 'octodns_etchosts.EtcHostsProvider',
19            'directory': './hosts',
20        },
21    },
22    'zones': {
23        'example.com.': {
24            'sources': ['config'],
25            'targets': ['etchosts'],
26        },
27    },
28}