Managing YUM repository list with The Foreman
What I missed in The Foreman’s default funtionality is the ability to automatically create Yum repo configuration files. For example, if you create a local CentOS mirror, you can specify it as Install Media in Foreman, and the autogenerated kickstart file will use it during the install. However, the installed systems will still get the default CentOS
.repo files, which is far from ideal. You want them to point to your local repository, which you used to install the systems.
Fortunately, it is very easy to generate contents for a
.repo file that would include all your local (or remote) repositories, which are assigned to the host’s Operating System.
Let’s quickly go through the host configuration data that involves OS and Installation Media settings (you can find all the under More dropdown menu in the Foreman UI).
- Host belongs to a Hostgroup
- Hostgroup points to a Operating System
- Operating System can have one or more Installation Medias
Once you correctly define all that, you’ll have to create new Configuration Template. Make sure you select Snippet checkbox, then paste the following template code:
<% @host.os.media.each do |media| -%> [<%= media.name.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '') %>] name=<%= media.name %> baseurl=<%= @host.os.medium_uri @host, media.path %> enabled=1 gpgcheck=0 <% end -%>
This snippet iterates though all Media records that are assigned to the current OS and renders the contents of Yum
Now in the provisioning template (I just updated ‘Kickstart Default’ that came predefined in Foreman), add this piece of code somewhere in the
rm -f /etc/yum.repos.d/* cat > /etc/yum.repos.d/system.repo << 'EOF' <%= snippet("Local OS repos") %> EOF
This will remove default OS repository definition files and will create a new one, containing all local repositories.
comments powered by Disqus