voxpupuli / puppet-yum

Puppet module for Yum
https://forge.puppet.com/puppet/yum
MIT License
16 stars 101 forks source link

How I can achieve puppet only managed repositories? #238

Closed KpuCko closed 1 year ago

KpuCko commented 2 years ago

Hello guys, I'm about to replace all of my manually managed repositories with the ones managed by puppet completely. So far so good, by using this module I'm able to populate all the repos via Hiera data (this is what I use) so I can differentiate between os_family, distro, hostname et cetera.

Here the problem arises, because there is nothing about - purge_default_repos, I'm looking forward to see how I can achieve this. For instance, I want to remove all the repos in /etc/yum.repos.d, then populate the folder with puppet created repos.

I think this can be done with simple exec, or file remove with recursive function for /etc/yum.repos.d, then execute the yum class after this, but because of lack of my knowledge, I'm not sure I'm on the right track.

Any suggestions and examples are more then welcomed. Thanks in advance.

Affected Puppet, Ruby, OS and module versions/distributions

kBite commented 2 years ago

@KpuCko I use a 'trick' to achieve that: using another directory instead and removing all *.repo files from /etc/yum.repos.d/

# ensure the 'reposdir' value is changed before deploying any repositories                                                       
Yumrepo { require => Yum::Config['reposdir'], }                                                                                  

file { '/etc/yum.managed-repos.d':                                                                                               
  ensure => 'directory',                                                                                                         
  owner  => 'root',                                                                                                              
  group  => 'root',                                                                                                              
  mode   => '0755',                                                                                                              
}                                                                                                                                

# changing the default directory to avoid name conflicts with exisiting                                                          
#   repository files and to minimize the number of active repositories                                                           
yum::config { 'reposdir':                                                                                                        
  ensure  => '/etc/yum.managed-repos.d',                                                                                         
  require => File['/etc/yum.managed-repos.d'],                                                                                   
}                                                                                                                                

# make sure no unnecessary repo files are present                                                                                
tidy { '/etc/yum.repos.d':                                                                                                       
  matches => [ '*.repo' ],                                                                                                       
  recurse => true,                                                                                                               
  backup  => false,                                                                                                              
  require => Yum::Config['reposdir'],                                                                                            
}                                                                                                                                

# create symlink for team members searching for repo files                                                                       
file { '/etc/yum.repos.d/you-are-looking-for':                                                                                   
  ensure  => 'link',                                                                                                             
  target  => '/etc/yum.managed-repos.d',                                                                                         
  require => File['/etc/yum.managed-repos.d'],                                                                                   
}                                                                                                                                

The result looks like this:

# ls -l /etc/yum.repos.d/                                                                                                        
total 0                                                                                                                          
lrwxrwxrwx 1 root root 24 Oct 23  2020 you-are-looking-for -> /etc/yum.managed-repos.d                                           

# ls -l /etc/yum.repos.d/you-are-looking-for/                                                                                    
total 56                                                                                                                         
-rw-r--r-- 1 root root 204 Oct 23  2020 centos_base.repo                                                                         
-rw-r--r-- 1 root root 212 Oct 23  2020 centos_extras.repo                                                                       
-rw-r--r-- 1 root root 215 Oct 23  2020 centos_updates.repo                                                                      
kenyon commented 1 year ago

258 attempted to add support for this, but didn't work. A way that works is here: https://github.com/voxpupuli/puppet-rhsm/pull/125#issuecomment-1204249388

kenyon commented 1 year ago

Duplicate of #104 and #94.