diff --git a/imageroot/bin/reload_hosts b/imageroot/bin/reload_hosts index 2a5fe95..edbdd3d 100755 --- a/imageroot/bin/reload_hosts +++ b/imageroot/bin/reload_hosts @@ -7,6 +7,7 @@ import json import subprocess +import os import agent import network @@ -30,9 +31,12 @@ if 'interface' in config and config['interface'] != '': # save a new configuration file for dnsmasq, so that it can resolve the CNAMEs to the node fqdn redis_client = agent.redis_connect(use_replica=True) + hosts = redis_client.smembers(f'{agent.resolve_agent_id("traefik@node")}/hosts') + # if there are hosts, write them to the file with open("dnsmasq.d/01cnames.conf", "w") as file: - file.write("# This file is automatically generated by NethServer, manual changes will be lost.\n") - file.write('cname=') - for host in redis_client.smembers(f'{agent.resolve_agent_id("traefik@node")}/hosts'): - file.write(f'{host},') - file.write(f'{fqdn}\n') + file.write("# This file is automatically generated by NethServer, manual changes will be lost.\n") + if len(hosts) > 0: + file.write('cname=') + for host in hosts: + file.write(f'{host},') + file.write(f'{fqdn}\n')