Sunday, June 26, 2011

Spacewalk provision Red Hat Linux by PXE kickstart

Spacewalk is an open source (GPLv2) Linux systems management solution. It is the upstream community project from which the Red Hat Network Satellite product is derived.
What can Spacewalk do:
- YUM repository Server, which is connected by client via yum-rhn-plugin
- Provision, kickstart, physical or virtual systems (using cobbler)
- Manage and deploy configuration files, software to a group of servers
- Monitor your systems (CPU, disk space etc .. ), Inventory your systems (hardware and software information)
OS supported by Spacewalk:
- Red Hat Linux derivatives (Centos, Fedora, Scientific Linux) and Solaris
- Limited support for SUSE Linux (AutoYaST Support is planned in V1.5, https://fedorahosted.org/spacewalk/roadmap )
- Experimental support for Debian (https://fedorahosted.org/spacewalk/wiki/Deb_support_in_spacewalk )
This post is not a complete guide for spacewalk install and administartion, its goal is to PXE kickstart a pysical server and have it registered to spacewalk server when kickstart complete. Kickstarting a server is easy but having it registered to spacewalk server needs tweaking.
Useful document for Spacewalk: 
http://wiki.centos.org/HowTos/PackageManagement/Spacewalk
https://fedorahosted.org/spacewalk/wiki/UserDocs
http://docs.redhat.com/docs/en-US/Red_Hat_Network_Satellite/index.html
This post demonstrate spacewalk 1.4 kickstarting Centos 5.5 i386
Steps Summary:
- Setup PXE boot server environment
- Create OS base channel
- Create child channel(tools channel)
- Create distribution tree
- Create activation key
- Create kickstart profile
Setup PXE boot server environment
Setup tftp and dhcpd, refer to http://honglus.blogspot.com/2011/06/setup-pxe-boot-server-for-linux-server.html
However, you don't bother editing pxelinux.cfg/default, which will be managed by spacewalk.
Create OS base channel
Navigate to: Channels | Manage software channels | Create new channel
Channel label is significant, It is channel label, not channel name, is referred for channel operations.
For GPG key section, refer to “GPG Sign RPM file” http://honglus.blogspot.com/2011/05/build-rpm-from-source-file.html
The GPG pub key need to copied to “/var/www/html/pub”, which can be downloaded by http://Server/pub/MY-GPG-FILE-NAME
#Import OS rpms to OS Base channel
#Before importing rpms, it is recommended to resign all rpms with your own GPG key “ rpm –resign *.rpm”, otherwise you need to import the rpm's original GPG key to all  clients.
$spacewalk-repo-sync  -c channel-label –-url  http://mirror.centos.org/centos/5/os/i386/
# You can also import rpms in installation media by –url file:///media/cdrom
Create child channel(tools channel)
Create a child channel for the Base channel created in last step, using same GPG information
#import spacewalk client rpms to the child channel
$spacewalk-repo-sync  -c child-channel-label  –-url  http://spacewalk.redhat.com/yum/1.4-client/RHEL/5/i386/
#python-ethtool doesn't exist in above sites, you need to download it manually from EPEL repository http://fedoraproject.org/wiki/EPEL  
#import a single rpm  to the child channel
$rhnpush  -c  child-channel-label  -u satadmin python-ethtool*.rpm 
Create distribution tree
Distribution hold installation files e.g. “images/stage2.img”, which can't be imported to spacewalk channel
#Create distribution tree path
$mkdir -p /var/distro-trees/centos-32-5.5
#Copy everything in installation media except for rpm files to the dir
#rpm files will be retrieved from channels
$cd /media/cdrom; find . ! -path "./CentOS/*"   | cpio -pvd /var/distro-trees/centos-32-5.5
Navigate to: Systems | Kickstart | Distributions | Create new distribution
dist2

Create activation key
Activation key is bound to base channel and entitlements, it is used by client to register to spacewalk without password authentication.
Navigate to: Systems | Activation Keys | Create new Key
Select the base channel and enable provisioning add-on entitlements
In child channels, select the child channel.
Optionally, if you want to pull configuration file e.g /etc/ntp.conf during kickstart, you need to create configuration channel and bind the activation key
Create kickstart profile
Navigate to: Systems | Kickstart | Create new kickstart profile
ks

In operating systems, select base channel and child channel
ks2
In Software,enter the  following packages in addition to @ Base
rhn-check
rhn-setup
yum-rhn-plugin
python-ethtool
python-dmidecode
rhncfg-client
rhncfg-actions
#Above packages provide rhnreg_ks and rhn_check to register to spacewalk during kickstart, otherwise kickstart postscript will encounter errors:
/tmp/ks-script-KOlpXy: line 128: rhnreg_ks: command not found
/tmp/ks-script-KOlpXy: line 134: rhn_check: command not found
#You can also write your own snipplets in “/var/lib/cobbler/snippets” to add packages dynamically.

In Activation Keys, select the activation key
Once kickstart profile is created, some entries are added to pxe configuration file
/tftpboot/pxelinux.cfg/default
Power on the server to be provisioned, when kickstart completed, It should be registered and appeared in spacewalk.

3 comments:

  1. hey dude please help me..
    when i run this command - #spacewalk-repo-sync -c mycent --url http://isoredirect.centos. org/centos/6/isos/x86_64/

    i got the following error -

    Traceback (most recent call last):
    File "/usr/bin/spacewalk-repo-sync", line 100, in
    sys.exit(abs(main() or 0))
    File "/usr/bin/spacewalk-repo-sync", line 93, in main
    sync.sync()
    File "/usr/lib/python2.6/site-packages/spacewalk/satellite_tools/reposync.py", line 100, in sync
    self.import_packages(plugin, repo_id, url)
    File "/usr/lib/python2.6/site-packages/spacewalk/satellite_tools/reposync.py", line 303, in import_packages
    packages = plug.list_packages(filters)
    File "/usr/lib/python2.6/site-packages/spacewalk/satellite_tools/repo_plugins/yum_src.py", line 151, in list_packages
    self.sack.populate(self.repo, 'metadata', None, 0)
    File "/usr/lib/python2.6/site-packages/yum/yumRepo.py", line 165, in populate
    if self._check_db_version(repo, mydbtype):
    File "/usr/lib/python2.6/site-packages/yum/yumRepo.py", line 223, in _check_db_version
    return repo._check_db_version(mdtype)
    File "/usr/lib/python2.6/site-packages/yum/yumRepo.py", line 1256, in _check_db_version
    repoXML = self.repoXML
    File "/usr/lib/python2.6/site-packages/yum/yumRepo.py", line 1455, in
    repoXML = property(fget=lambda self: self._getRepoXML(),
    File "/usr/lib/python2.6/site-packages/yum/yumRepo.py", line 1451, in _getRepoXML
    raise Errors.RepoError, msg
    yum.Errors.RepoError: Cannot retrieve repository metadata (repomd.xml) for repository: mycent. Please verify its path and try again


    Please help me on this asap.

    ReplyDelete
    Replies
    1. The default CentOS distribution does not contain the spacewalk client packages. How should i add them?

      rhn-check

      rhn-setup

      yum-rhn-plugin

      python-ethtool

      python-dmidecode

      rhncfg-client

      rhncfg-actions

      Delete
  2. Add the spacewalk-clients repo and channel -- here's the repo URL: http://yum.spacewalkproject.org/2.3-client/RHEL/6/x86_64/

    You should be able to install the missing pieces now.

    Consider the osad package, which provides immediate remediation instead of a timed checkin (it pokes the client via jabber and makes it rhn_check NOW).

    Good Luck!

    ReplyDelete