From 1260410eae1d770ee25c350585d737f1717714b9 Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Tue, 16 May 2023 19:56:21 +0200 Subject: [PATCH] bundles/powerdns: split "add ip to autoprimaries" and "fix hostname for autoprimary" --- bundles/powerdns/items.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/bundles/powerdns/items.py b/bundles/powerdns/items.py index ddb8751..04261c0 100644 --- a/bundles/powerdns/items.py +++ b/bundles/powerdns/items.py @@ -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'] = {