2

I install CentOS 7 using the ks=http://10.0.0.100:8080/anaconda-ks.cfg option and I serve the static configuration file by running a simple web server: python -m SimpleHTTPServer 8080.

In my anaconda-ks.cfg I currently set the hostname like this:

network  --hostname=centdev

However, I wish to read a text file (preferably JSON using Python) from the same location as my anaconda-ks.cfg and check the current hardware ID against a dictionary to figure out which hostname to use.

  1. Can I somehow avoid hardcoding http://10.0.0.100:8080 into anaconda-ks.cfg and fetch this location via e.g. a an environment variable?

  2. Do I just embed my python script inside of anaconda-ks.cfg using the %pre like below?


%pre
#!/bin/python
print 'Read JSON file here...'
%end
fredrik
  • 731
  • 15
  • 20

1 Answers1

1

This is what I did... I added the following into my anaconda-ks.cfg script:

# 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"
fredrik
  • 731
  • 15
  • 20
  • Please consider accepting an answer, even if it is your own. Nice that you got it working, you can put whatever you like in pre and post scripts. – John Mahowald Dec 31 '15 at 16:38