Last active
February 15, 2017 06:32
-
-
Save adamcrews/f59865d019718eac3fa5004bb61298cc to your computer and use it in GitHub Desktop.
purgeable yumrepo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define std_yumrepo ( | |
String $repo_name = $title, | |
Optional[Enum['absent', 'present', 'absent']] $ensure = present, | |
Optional[Variant[Enum['absent'], Pattern[/^(true|false|0|1|no|yes)$/]]] $assumeyes = absent, | |
Optional[Variant[Enum['absent'], Pattern[/^\d+[kMG]?$/]]] $bandwidth = absent, | |
Optional[String] $baseurl = absent, | |
Optional[Variant[Enum['absent'], Integer]] $cost = absent, | |
Optional[Variant[Enum['absent'], Integer]] $deltarpm_metadata_percentage = absent, | |
Optional[Variant[Enum['absent'], Integer]] $deltarpm_percentage = absent, | |
Optional[String] $descr = absent, | |
Optional[Variant[Enum['absent'], Pattern[/^(true|false|0|1|no|yes)$/]]] $enabled = absent, | |
Optional[Variant[Enum['absent'], Pattern[/^(true|false|0|1|no|yes)$/]]] $enablegroups = absent, | |
Optional[String] $exclude = absent, | |
Optional[Enum['absent', 'roundrobin', 'priority']] $failovermethod = absent, | |
Optional[String] $gpgcakey = absent, | |
Optional[Variant[Enum['absent'], Pattern[/^(true|false|0|1|no|yes)$/]]] $gpgcheck = absent, | |
Optional[Variant[String, Array[String]]] $gpgkey = absent, | |
Optional[Enum['absent', 'packages', 'all', 'none']] $http_caching = absent, | |
Optional[String] $include = absent, | |
Optional[String] $includepkgs = absent, | |
Optional[Variant[Enum['absent'], Pattern[/^(true|false|0|1|no|yes)$/]]] $keepalive = absent, | |
Optional[Variant[Enum['absent'], Pattern[/^([0-9]+[dhm]?|never)$/]]] $metadata_expire = absent, | |
Optional[String] $metalink = absent, | |
Optional[String] $mirrorlist = absent, | |
Optional[Variant[Enum['absent'], Integer]] $mirrorlist_expire = absent, | |
Optional[String] $priority = absent, | |
Optional[Variant[Enum['absent'], Pattern[/^(true|false|0|1|no|yes)$/]]] $protect = absent, | |
Optional[Enum['inifile']] $provider = inifile, | |
Optional[String] $proxy = absent, | |
Optional[String] $proxy_password = absent, | |
Optional[String] $proxy_username = absent, | |
Optional[Variant[Enum['absent'], Pattern[/^(true|false|0|1|no|yes)$/]]] $repo_gpgcheck = absent, | |
Optional[Variant[Enum['absent'], Integer]] $retries = absent, | |
Optional[Variant[Enum['absent'], Pattern[/^(true|false|0|1|no|yes)$/]]] $s3_enabled = absent, | |
Optional[Variant[Enum['absent'], Pattern[/^(true|false|0|1|no|yes)$/]]] $skip_if_unavailable = absent, | |
Optional[String] $sslcacert = absent, | |
Optional[String] $sslclientcert = absent, | |
Optional[String] $sslclientkey = absent, | |
Optional[Variant[Enum['absent'], Pattern[/^(true|false|0|1|no|yes)$/]]] $sslverify = absent, | |
Optional[String] $target = undef, | |
Optional[Variant[Enum['absent'], Pattern[/^\d+[kMG%]?$/]]] $throttle = absent, | |
Optional[Variant[Enum['absent'], Integer]] $timeout = absent | |
) { | |
yumrepo { $repo_name: | |
ensure => $ensure, | |
assumeyes => $assumeyes, | |
bandwidth => $bandwidth, | |
baseurl => $baseurl, | |
cost => $cost, | |
deltarpm_metadata_percentage => $deltarpm_metadata_percentage, | |
deltarpm_percentage => $deltarpm_metadata_percentage, | |
descr => $descr, | |
enabled => $enabled, | |
enablegroups => $enablegroups, | |
exclude => $exclude, | |
failovermethod => $failovermethod, | |
gpgcakey => $gpgcakey, | |
gpgcheck => $gpgcheck, | |
gpgkey => $gpgkey, | |
http_caching => $http_caching, | |
include => $include, | |
includepkgs => $includepkgs, | |
keepalive => $keepalive, | |
metadata_expire => $metadata_expire, | |
metalink => $metalink, | |
mirrorlist => $mirrorlist, | |
mirrorlist_expire => $mirrorlist_expire, | |
priority => $priority, | |
protect => $protect, | |
provider => $provider, | |
proxy => $proxy, | |
proxy_password => $proxy_password, | |
proxy_username => $proxy_username, | |
repo_gpgcheck => $repo_gpgcheck, | |
retries => $retries, | |
s3_enabled => $s3_enabled, | |
skip_if_unavailable => $skip_if_unavailable, | |
sslcacert => $sslcacert, | |
sslclientcert => $sslclientcert, | |
sslclientkey => $sslclientkey, | |
sslverify => $sslverify, | |
target => $target, | |
throttle => $throttle, | |
timeout => $timeout, | |
} | |
file { "/etc/yum.repos.d/${repo_name}.repo": | |
ensure => $ensure, | |
require => Yumrepo[$repo_name], | |
} | |
} | |
file { '/etc/yum.repos.d': | |
ensure => directory, | |
purge => true, | |
recurse => true, | |
force => true, | |
} | |
std_yumrepo { 'base': | |
ensure => 'present', | |
descr => 'CentOS-$releasever - Base', | |
gpgcheck => '1', | |
gpgkey => 'file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7', | |
mirrorlist => 'http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra', | |
} | |
std_yumrepo { 'puppetlabs-pc1': | |
ensure => 'present', | |
baseurl => 'http://yum.puppetlabs.com/el/7/PC1/$basearch', | |
descr => 'Puppet Labs PC1 Repository el 7 - $basearch', | |
enabled => '1', | |
gpgcheck => '1', | |
gpgkey => 'file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs-PC1 | |
file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puppet-PC1', | |
} | |
std_yumrepo { 'foo': | |
ensure => 'absent', | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'puppet' | |
require 'puppet/util/inifile' | |
Facter.add(:yumrepos) do | |
setcode do | |
# Much of this code was inspired from the inifile provider for | |
# the yumrepo type in the puppet source code. | |
# This was done because some yum files contain multiple values | |
# to a single key (gpgkey is an example). Since there is no | |
# real standard for an inifile, this logic parses the yumrepos | |
# the same way puppet does internally, so the fact should be | |
# the same output as a puppet yumrepo instance. | |
yumrepos = {} | |
def self.virtual_inifile | |
unless @virtual | |
@virtual = Puppet::Util::IniConfig::File.new | |
Dir.glob("/etc/yum.repos.d/*.repo").each do |file| | |
@virtual.read(file) if Puppet::FileSystem.file?(file) | |
end | |
end | |
return @virtual | |
end | |
virtual_inifile.each_section do |section| | |
repo_hash = {:name => section.name } | |
section.entries.each do |key, value| | |
key = key.to_sym | |
if key == :name | |
repo_hash[:descr] = value | |
else | |
repo_hash[key] = value.include?("\n") ? value.gsub(' ', '').split("\n") : value | |
end | |
end | |
yumrepos[section.name] = repo_hash | |
end | |
yumrepos | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment