Centos kickstart script url installation with mirror

centoskickstart

I have a ks script to install Centos6.5.
Inside my local network I have a snapshot of the base package mirror.

I want to used as possible as I can my local package site over extranet like http://mirrors.kernel.org/centos/6.5/os/x86_64/.

However, the ks script should work outside the local network so I need to define some fallback/mirror url.

In fedora environment there is an option for url directive http://fedoraproject.org/wiki/Anaconda/Kickstart#url --mirrorlist but its option does not exists for Centos6.5.

There is any way other solution to manage my problem?

I thought about %pre bash script but without any package it will be hard to test which url I have to choose.

Best Answer

I would create a %pre Python script and use urllib2.urlopen() to check whether your local repository is available. If not, it would use one of the mirrors online.

See example usage here: https://stackoverflow.com/questions/16778435/python-check-if-website-exists

So, for example:

%pre --interpreter=/usr/bin/python

import urllib2

local_url = 'http://localserver/CentOS/6/os/'
remote_url = 'http://mirror.zetup.net/CentOS/6/os/'

# Determine which URL to use
try:
    urllib2.urlopen(local_url)
    my_url = local_url
except urllib2.URLError:
    my_url = remote_url

# Write the .ks file
with open('/tmp/install-url.ks', 'w') as f:
    f.write('url --url=' + my_url)
%end

# Network installation
%include '/tmp/install-url.ks'