mirror of
https://github.com/nchevsky/systemrescue-zfs.git
synced 2025-12-06 07:12:01 +01:00
Merge branch 'hosts-yaml' into 'main'
support configuring entries for the /etc/hosts file in the YAML config See merge request systemrescue/systemrescue-sources!251
This commit is contained in:
commit
755c5215cf
|
|
@ -122,6 +122,27 @@ if 'sysconfig' in config and 'sysctl' in config['sysconfig'] and \
|
|||
print (f"Some or all sysctl options couldn't be set")
|
||||
errcnt+=1
|
||||
|
||||
# ==============================================================================
|
||||
# configure hosts file
|
||||
# Should be pre-network to be available throughout the whole network setup
|
||||
# ==============================================================================
|
||||
|
||||
if 'sysconfig' in config and 'hosts' in config['sysconfig'] and \
|
||||
config['sysconfig']['hosts'] and isinstance(config['sysconfig']['hosts'], dict):
|
||||
print(f"====> Configuring /etc/hosts ...")
|
||||
|
||||
try:
|
||||
# append all our entries to the hosts file
|
||||
with open("/etc/hosts", "a") as hostsfile:
|
||||
# key is the IPv4/IPv6, value the hostname(s)
|
||||
for ip, hostname in config['sysconfig']['hosts'].items():
|
||||
hostsfile.write(f"{ip}\t{hostname}\n")
|
||||
hostsfile.close()
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
errcnt+=1
|
||||
|
||||
# ==============================================================================
|
||||
# End of the script
|
||||
# ==============================================================================
|
||||
|
|
|
|||
Loading…
Reference in a new issue