bundles/powerdns: split "add ip to autoprimaries" and "fix hostname for autoprimary"

This commit is contained in:
Franzi 2023-05-16 19:56:21 +02:00
parent 261c284f2f
commit 1260410eae
Signed by: kunsi
GPG key ID: 12E3D2136B818350

View file

@ -175,14 +175,27 @@ if node.metadata.get('powerdns/features/pgsql', node.has_bundle('postgresql')):
for hostname, ips in node.metadata.get('powerdns/my_primary_servers', {}).items():
for ip in ips:
ip_name = ip.replace(':', '-')
actions[f'powerdns_ensure_{hostname}_{ip_name}_in_autoprimaries'] = {
'command': 'psql -c "INSERT INTO supermasters (ip, nameserver, account) VALUES '
f'(\'{ip}\', \'{hostname}\', \'admin\') ON CONFLICT ON CONSTRAINT '
f'supermasters_pkey DO UPDATE SET nameserver = \'{hostname}\'" powerdns',
actions[f'powerdns_ensure_{ip_name}_in_autoprimaries'] = {
'command': f'psql -c "INSERT INTO supermasters (ip, nameserver, account) VALUES (\'{ip}\', \'{hostname}\', \'admin\')" powerdns',
'unless': f'test -n \"$(psql -tAqc "SELECT nameserver FROM supermasters WHERE ip = \'{ip}\'" powerdns)\"',
'triggers': {
'action:powerdns_fix_primaries',
},
'after': {
'action:powerdns_load_pgsql_schema',
},
}
actions[f'powerdns_ensure_{hostname}_matches_{ip_name}_in_autoprimaries'] = {
'command': f'psql -c "UPDATE supermasters SET nameserver = \'{hostname}\' WHERE ip = \'{ip}\'" powerdns',
'unless': f'bash -c "[ \"$(psql -tAqc "SELECT nameserver FROM supermasters WHERE ip = \'{ip}\'" powerdns)\" == \"{hostname}\" ]"',
'triggers': {
'action:powerdns_fix_primaries',
},
'after': {
f'action:powerdns_ensure_{ip_name}_in_autoprimaries',
},
}
actions['powerdns_fix_primaries'] = {