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.

It's a simplistic idea, allowing you to create a custom package repository so that Puppet can make use of it's package resource type. Once yum is made aware of the custom repository, it can run the necessary queries, and packages can be retrieved and installed as desired.

Creating a custom repository

All this can be achieved in three simple steps:

  1. Download the RPMs
  2. Create the repository metadata
  3. 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:

  1. Firstly, make sure you have an apache server installed and that a valid hostname and port 80 is reachable across your network
  2. Ensure createrepo is installed on your repository host
    yum install createrepo
  3. 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.
  4. 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 run createrepo in each of those directories, for example:
    cd /var/www/repository/i386
    createrepo .
    cd ../x86_64
    createrepo .
  5. Change the ownership of /var/www/repositiory recursively to reflect the owner/group of the http service, For example
    chown -R www-data:www-data /var/www/repository
  6. On the systems that will use the custom repository, place the following text file in /etc/yum.repos.d directory, For example:
    name = My Repository
    baseurl = http://localhost/repository
    I guess, you could achieve the same with a puppet file resource file populating the content to point to the customer repository.
  7. 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.
  8. Now, simply use the puppet package resource as normal and the custom repository will be utilised when installing new packages