2525logging.basicConfig(format='[%(levelname)s] %(message)s', level=logging.INFO)
2626
2727def generate_answerfile(directory, installer, hostname_or_ip, target_hostname, action, hdd, netinstall_gpg_check):
28- password = host_data(hostname_or_ip)['password']
28+ h_data = host_data(hostname_or_ip)
29+ password = h_data['password']
30+ if 'ip' in h_data:
31+ iface = f"""
32+ <admin-interface name="eth0" proto="static">
33+ <ipaddr>{h_data['ip']}</ipaddr>
34+ <subnet>{h_data['netmask']}</subnet>
35+ <gateway>{h_data['gw']}</gateway>
36+ </admin-interface>
37+ <name-server>{h_data['dns']}</name-server>
38+ """
39+ else:
40+ iface = '<admin-interface name="eth0" proto="dhcp" />'
2941 cmd = ['openssl', 'passwd', '-6', password]
3042 res = subprocess.run(cmd, stdout=subprocess.PIPE)
3143 encrypted_password = res.stdout.decode().strip()
@@ -42,7 +54,7 @@ def generate_answerfile(directory, installer, hostname_or_ip, target_hostname, a
4254 <guest-disk>{hdd}</guest-disk>
4355 <root-password type="hash">{encrypted_password}</root-password>
4456 <source type="url">{installer}</source>
45- <admin-interface name="eth0" proto="dhcp" />
57+ {iface}
4658 <timezone>Europe/Paris</timezone>
4759 <hostname>{target_hostname}</hostname>
4860 <script stage="filesystem-populated" type="url">
0 commit comments