Creating a local yum repository for Puppet
I came across a RHEL utility the other day named createrepo
which allows you to create the necessary metadata to host a yum repository locally. This utility seems to examine RPMS in a given repository and then generates XML RPM metadata which yum queries to determine available packages.
Creating a custom repository
All this can be achieved in three simple steps:
- Download the RPMs
- Create the repository metadata
- Make the repository metadata and RPMs available on your network via an apache server
Setting up a basic repository
A very basic repository could be constructed on RH based systems using the following steps:
- Firstly, make sure you have an apache server installed and that a valid hostname and port 80 is reachable across your network
- Ensure
createrepo
is installed on your repository hostyum install createrepo
- Decide wherre you want to store your repository, download place all the necessary RPMs into the desired location.
For example:
/var/www/repository
Whilst the above is generic and all RPMs will be placed in a single repository, you could if desired keep them organised and have i386 and x86_64 packages separately, For exampe:mkdir -p /var/www/repository/{i386,x86_64}
And copy your packages to the necessary directories. - Run createrepo again your repository location, for example:
createrepo /var/www/repository
Again, if you have separated out your i386/x86_64 packages, you will then need to runcreaterepo
in each of those directories, for example:cd /var/www/repository/i386 createrepo . cd ../x86_64 createrepo .
- Change the ownership of
/var/www/repositiory
recursively to reflect the owner/group of the http service, For examplechown -R www-data:www-data /var/www/repository
- On the systems that will use the custom repository, place the following text file in /etc/yum.repos.d directory, For example:
[myrepo] name = My Repository baseurl = http://localhost/repository gpgcheck=0 enabled=1
I guess, you could achieve the same with a puppet file resource file populating the content to point to the customer repository. - On a system that will use this custom repository, attempt to search for one of the RPMs you are hosting. Hey presto! You should now be able to locate the package.
- Now, simply use the puppet package resource as normal and the custom repository will be utilised when installing new packages