25
25
logging .basicConfig (format = '[%(levelname)s] %(message)s' , level = logging .INFO )
26
26
27
27
def 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" />'
29
41
cmd = ['openssl' , 'passwd' , '-6' , password ]
30
42
res = subprocess .run (cmd , stdout = subprocess .PIPE )
31
43
encrypted_password = res .stdout .decode ().strip ()
@@ -42,7 +54,7 @@ def generate_answerfile(directory, installer, hostname_or_ip, target_hostname, a
42
54
<guest-disk>{ hdd } </guest-disk>
43
55
<root-password type="hash">{ encrypted_password } </root-password>
44
56
<source type="url">{ installer } </source>
45
- <admin-interface name="eth0" proto="dhcp" />
57
+ { iface }
46
58
<timezone>Europe/Paris</timezone>
47
59
<hostname>{ target_hostname } </hostname>
48
60
<script stage="filesystem-populated" type="url">
0 commit comments