CentOS:如何在kickstart脚本中设置基于外部文件的主机名?

我使用ks=http://10.0.0.100:8080/anaconda-ks.cfg选项安装CentOS 7,并通过运行简单的Web服务器来提供静态configuration文件: python -m SimpleHTTPServer 8080

在我的anaconda-ks.cfg我目前设置的主机名是这样的:

 network --hostname=centdev 

但是,我希望从与anaconda-ks.cfg相同的位置读取文本文件(最好使用Python的JSON),并根据字典检查当前的硬件ID以确定使用哪个主机名。

  1. 我可以以某种方式避免硬编码http://10.0.0.100:8080到anaconda-ks.cfg并通过例如一个环境variables获取这个位置?

  2. 我是否像下面使用%preembedded我的python脚本内anaconda-ks.cfg


 %pre #!/bin/python print 'Read JSON file here...' %end 

这就是我所做的…我将以下内容添加到我的anaconda-ks.cfg脚本中:

 # Pre python %pre --interpreter=/usr/bin/python print 'python code goes here to define "myhostname"' ... hfile = open("/tmp/hostname.ks", "w") hfile.write("network --hostname=" + myhostname) hfile.close() %end # Network information network --bootproto=dhcp --device=eth0 --ipv6=auto --activate %include "/tmp/hostname.ks"