diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..4f662dc --- /dev/null +++ b/Gemfile @@ -0,0 +1,18 @@ +source ENV['GEM_SOURCE'] || 'https://rubygems.org' + +puppetversion = ENV.key?('PUPPET_VERSION') ? ENV['PUPPET_VERSION'] : ['>= 3.3'] +gem 'metadata-json-lint' +gem 'puppet', puppetversion +gem 'puppetlabs_spec_helper', '>= 1.0.0' +gem 'puppet-lint', '>= 1.0.0' +gem 'facter', '>= 1.7.0' +gem 'rspec-puppet' + +# rspec must be v2 for ruby 1.8.7 +if RUBY_VERSION >= '1.8.7' && RUBY_VERSION < '1.9' + gem 'rspec', '~> 2.0' + gem 'rake', '~> 10.0' +else + # rubocop requires ruby >= 1.9 + gem 'rubocop' +end diff --git a/README.md b/README.md new file mode 100644 index 0000000..eefda42 --- /dev/null +++ b/README.md @@ -0,0 +1,149 @@ +# mirror_repos + +#### Table of Contents + +1. [Description](#description) +2. [Setup - The basics of getting started with mirror_repos](#setup) + * [Beginning with mirror_repos](#beginning-with-mirror_repos) +3. [Usage - Configuration options and additional functionality](#examples) +4. [Reference - An under-the-hood peek at what the module is doing and how](#reference) +5. [Limitations - OS compatibility, etc.](#limitations) +6. [Development - Guide for contributing to the module](#development) + +## Description + +`puppetlabs-apache` module if you want to manage vhost within this module. +apache module create a http proxy with fqdn of the hostname. + +This module copy all available rpms from given repo_source using reposync and +then create repository using createrepo from all rpms. + +## Setup + +Repo configuration should be a Hash in following format +`mirror_repos::repos:` must be followed by `OS-ARCH` and then +name of the repo and configuration of repo + +### Beginning with mirror_repos + +This module copy a bash script `update-repos` to /usr/sbin. +This script runs every night to sync remote repos. +This script has many options, to know more do `/usr/sbin/update-repos -h`. + +#### Examples + +##### + +It is highly recommended to define repos in Hiera. +``` +mirror_repos::config_dir: '/etc/repos' +mirror_repos::repos_dir: '/n/repos' +mirror_repos::repos: + centos7-x86_64: + base: + baseurl: 'http://mirrors.tripadvisor.com/centos/7/os/x86_64/' + gpgkey: 'http://mirrors.tripadvisor.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7' + enabled: 1 + centos6-x86_64: + base: + baseurl: 'http://mirror.centos.org/centos-6/6/os/x86_64/' + enabled: 0 +``` + +## Reference + +#### Parameters + +The following parameters are available in the `mirror_repos` class. + +##### `packages` + +Data type: `Array` + + + +Default value: $mirror_repos::params::packages + +##### `repos` + +Data type: `Hash` + + + +Default value: $mirror_repos::params::repos + +##### `vhosts` + +Data type: `Hash` + + +Default value: $mirror_repos::params::vhosts + +##### `config_dir` + +Data type: `String` + + +Default value: $mirror_repos::params::config_dir + +##### `repos_dir` + +Data type: `String` + + +Default value: $mirror_repos::params::repos_dir + +##### `manage_vhost` + +Data type: `Boolean` + + +Default value: $mirror_repos::params::manage_vhost + + +### mirror_repos::apache + +The mirror_repos::apache class. + +### mirror_repos::config + +== Class mirror_repos::config + +This class is called from mirror_repos + +### mirror_repos::install + +The mirror_repos::install class. + +### mirror_repos::params + +The mirror_repos::params class. + +## Limitations + +This Module is tested on RedHat7 and CentOS7. + +## Development + +For contributing Fork this module and open PR. + +Authors +------- + +Bhanu Prasad G + +Copyright +--------- +Copyright [2018] [Bhanu Prasad G] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..02609e3 --- /dev/null +++ b/Rakefile @@ -0,0 +1,32 @@ +require 'puppetlabs_spec_helper/rake_tasks' +require 'puppet-lint/tasks/puppet-lint' +require 'metadata-json-lint/rake_task' + +if RUBY_VERSION >= '1.9' + require 'rubocop/rake_task' + RuboCop::RakeTask.new +end + +PuppetLint.configuration.send('disable_80chars') +PuppetLint.configuration.relative = true +PuppetLint.configuration.ignore_paths = ['spec/**/*.pp', 'pkg/**/*.pp'] + +desc 'Validate manifests, templates, and ruby files' +task :validate do + Dir['manifests/**/*.pp'].each do |manifest| + sh "puppet parser validate --noop #{manifest}" + end + Dir['spec/**/*.rb', 'lib/**/*.rb'].each do |ruby_file| + sh "ruby -c #{ruby_file}" unless ruby_file =~ %r{spec/fixtures} + end + Dir['templates/**/*.erb'].each do |template| + sh "erb -P -x -T '-' #{template} | ruby -c" + end +end + +desc 'Run metadata_lint, lint, validate, and spec tests.' +task :test do + [:metadata_lint, :lint, :validate, :spec].each do |test| + Rake::Task[test].invoke + end +end diff --git a/examples/init.pp b/examples/init.pp new file mode 100644 index 0000000..47f7525 --- /dev/null +++ b/examples/init.pp @@ -0,0 +1,12 @@ +# The baseline for module testing used by Puppet Labs is that each manifest +# should have a corresponding test manifest that declares that class or defined +# type. +# +# Tests are then run by using puppet apply --noop (to check for compilation +# errors and view a log of events) or by fully applying the test in a virtual +# environment (to compare the resulting system state to the desired state). +# +# Learn more about module testing here: +# https://docs.puppet.com/guides/tests_smoke.html +# +include ::mirror_repos diff --git a/manifests/apache.pp b/manifests/apache.pp new file mode 100644 index 0000000..b26da51 --- /dev/null +++ b/manifests/apache.pp @@ -0,0 +1,16 @@ +class mirror_repos::apache { + if $mirror_repos::manage_vhost { + include ::apache + include ::apache::mod::proxy + + if $mirror_repos::vhosts == {} { + apache::vhost { $::fqdn: + port => '80', + docroot => $mirror_repos::repos_dir, + } + } + else { + create_resources('apache::vhost',$mirror_repos::vhosts) + } + } +} diff --git a/manifests/config.pp b/manifests/config.pp new file mode 100644 index 0000000..9b315a8 --- /dev/null +++ b/manifests/config.pp @@ -0,0 +1,34 @@ +# == Class mirror_repos::config +# +# This class is called from mirror_repos +# +class mirror_repos::config { + #just replicate yum.repos.d + file { [ $mirror_repos::config_dir, $mirror_repos::repos_dir ]: + ensure => directory, + } + #create a dir for each OS and then a file for each repo under that OS + $mirror_repos::repos.each |String $os_name , $repos_os | { + $os = regsubst($os_name, '[-]', '_', 'G') + file {"${mirror_repos::config_dir}/${os}.conf": + ensure => 'file', + mode => '0644', + content => template('mirror_repos/repo.conf.erb'), + } + } + $oses = keys($mirror_repos::repos) + #copy file to update repos to localhost + file { '/usr/sbin/update-repos': + ensure => file, + mode => '0755', + content => template('mirror_repos/update-repos.sh.erb'), + } + #run cron every night to update repos + cron { 'update-repos': + command => '/usr/sbin/update-repos', + user => 'root', + hour => 1, + minute => 0, + require => File['/usr/sbin/update-repos'], + } +} diff --git a/manifests/init.pp b/manifests/init.pp new file mode 100644 index 0000000..4ee01d3 --- /dev/null +++ b/manifests/init.pp @@ -0,0 +1,49 @@ +# Class: mirror_repos +# =========================== +# +# Full description of class mirror_repos here. +# +# Parameters +# ---------- +# +# * `mirror_repos::vhost` +# create apache vhost with this name. Default is FQDN +# +# Variables +# ---------- +# +# * `mirror_repos::config_dir` +# Where to deploy the repo configuration files. +# Default is `/etc/mirror.repos.d` +# +# * `mirror_repos::repos_dir` +# Where to store the mirrorred repos +# Default is `/repos` +# +# * `mirror_repos::repos` +# repositories to mirror +# Default is empty +# +# Examples +# #### +# -------- +# +# @example +# class { 'mirror_repos': +# config_dir => '/etc/repos_conf', +# } +# +# +class mirror_repos ( + Array $packages = $mirror_repos::params::packages, + Hash $repos = $mirror_repos::params::repos, + Hash $vhosts = $mirror_repos::params::vhosts, + String $config_dir = $mirror_repos::params::config_dir, + String $repos_dir = $mirror_repos::params::repos_dir, + Boolean $manage_vhost = $mirror_repos::params::manage_vhost, + ) inherits mirror_repos::params { + + class { '::mirror_repos::install': } + -> class { '::mirror_repos::config': } + -> class { '::mirror_repos::apache': } +} diff --git a/manifests/install.pp b/manifests/install.pp new file mode 100644 index 0000000..35c26bc --- /dev/null +++ b/manifests/install.pp @@ -0,0 +1,5 @@ +class mirror_repos::install { + package { $mirror_repos::packages: + ensure => present, + } +} diff --git a/manifests/params.pp b/manifests/params.pp new file mode 100644 index 0000000..4d48ab8 --- /dev/null +++ b/manifests/params.pp @@ -0,0 +1,15 @@ +class mirror_repos::params { + case $::osfamily { + 'RedHat': { + $packages = ['createrepo', 'yum-utils'] + $manage_vhost = true + $vhosts = {} + $config_dir = '/etc/mirror.repos.d' + $repos_dir = '/repos' + $repos = {} + } + default: { + fail("${::operatingsystem} not supported") + } + } +} diff --git a/metadata.json b/metadata.json new file mode 100644 index 0000000..752c3fd --- /dev/null +++ b/metadata.json @@ -0,0 +1,15 @@ +{ + "name": "bp85-mirror_repos", + "version": "0.1.0", + "author": "bp85", + "summary": "Mirror yum repositories to local + and create yum repos from those", + "license": "Apache-2.0", + "source": "https://github.com/bp85/puppet-mirror_repos", + "project_page": "https://github.com/bp85/puppet-mirror_repos", + "issues_url": "https://github.com/bp85/puppet-mirror_repos/issues", + "dependencies": [ + {"name":"puppetlabs-stdlib","version_requirement":">= 1.0.0"}, + {"name":"puppetlabs-apache","version_requirement":">=1.11.0"} + ], + "data_provider": null +} diff --git a/pkg/bp85-mirror_repos-0.1.0.tar.gz b/pkg/bp85-mirror_repos-0.1.0.tar.gz new file mode 100644 index 0000000..dfaf2de Binary files /dev/null and b/pkg/bp85-mirror_repos-0.1.0.tar.gz differ diff --git a/pkg/bp85-mirror_repos-0.1.0/Gemfile b/pkg/bp85-mirror_repos-0.1.0/Gemfile new file mode 100644 index 0000000..4f662dc --- /dev/null +++ b/pkg/bp85-mirror_repos-0.1.0/Gemfile @@ -0,0 +1,18 @@ +source ENV['GEM_SOURCE'] || 'https://rubygems.org' + +puppetversion = ENV.key?('PUPPET_VERSION') ? ENV['PUPPET_VERSION'] : ['>= 3.3'] +gem 'metadata-json-lint' +gem 'puppet', puppetversion +gem 'puppetlabs_spec_helper', '>= 1.0.0' +gem 'puppet-lint', '>= 1.0.0' +gem 'facter', '>= 1.7.0' +gem 'rspec-puppet' + +# rspec must be v2 for ruby 1.8.7 +if RUBY_VERSION >= '1.8.7' && RUBY_VERSION < '1.9' + gem 'rspec', '~> 2.0' + gem 'rake', '~> 10.0' +else + # rubocop requires ruby >= 1.9 + gem 'rubocop' +end diff --git a/pkg/bp85-mirror_repos-0.1.0/README.md b/pkg/bp85-mirror_repos-0.1.0/README.md new file mode 100644 index 0000000..eefda42 --- /dev/null +++ b/pkg/bp85-mirror_repos-0.1.0/README.md @@ -0,0 +1,149 @@ +# mirror_repos + +#### Table of Contents + +1. [Description](#description) +2. [Setup - The basics of getting started with mirror_repos](#setup) + * [Beginning with mirror_repos](#beginning-with-mirror_repos) +3. [Usage - Configuration options and additional functionality](#examples) +4. [Reference - An under-the-hood peek at what the module is doing and how](#reference) +5. [Limitations - OS compatibility, etc.](#limitations) +6. [Development - Guide for contributing to the module](#development) + +## Description + +`puppetlabs-apache` module if you want to manage vhost within this module. +apache module create a http proxy with fqdn of the hostname. + +This module copy all available rpms from given repo_source using reposync and +then create repository using createrepo from all rpms. + +## Setup + +Repo configuration should be a Hash in following format +`mirror_repos::repos:` must be followed by `OS-ARCH` and then +name of the repo and configuration of repo + +### Beginning with mirror_repos + +This module copy a bash script `update-repos` to /usr/sbin. +This script runs every night to sync remote repos. +This script has many options, to know more do `/usr/sbin/update-repos -h`. + +#### Examples + +##### + +It is highly recommended to define repos in Hiera. +``` +mirror_repos::config_dir: '/etc/repos' +mirror_repos::repos_dir: '/n/repos' +mirror_repos::repos: + centos7-x86_64: + base: + baseurl: 'http://mirrors.tripadvisor.com/centos/7/os/x86_64/' + gpgkey: 'http://mirrors.tripadvisor.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7' + enabled: 1 + centos6-x86_64: + base: + baseurl: 'http://mirror.centos.org/centos-6/6/os/x86_64/' + enabled: 0 +``` + +## Reference + +#### Parameters + +The following parameters are available in the `mirror_repos` class. + +##### `packages` + +Data type: `Array` + + + +Default value: $mirror_repos::params::packages + +##### `repos` + +Data type: `Hash` + + + +Default value: $mirror_repos::params::repos + +##### `vhosts` + +Data type: `Hash` + + +Default value: $mirror_repos::params::vhosts + +##### `config_dir` + +Data type: `String` + + +Default value: $mirror_repos::params::config_dir + +##### `repos_dir` + +Data type: `String` + + +Default value: $mirror_repos::params::repos_dir + +##### `manage_vhost` + +Data type: `Boolean` + + +Default value: $mirror_repos::params::manage_vhost + + +### mirror_repos::apache + +The mirror_repos::apache class. + +### mirror_repos::config + +== Class mirror_repos::config + +This class is called from mirror_repos + +### mirror_repos::install + +The mirror_repos::install class. + +### mirror_repos::params + +The mirror_repos::params class. + +## Limitations + +This Module is tested on RedHat7 and CentOS7. + +## Development + +For contributing Fork this module and open PR. + +Authors +------- + +Bhanu Prasad G + +Copyright +--------- +Copyright [2018] [Bhanu Prasad G] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/pkg/bp85-mirror_repos-0.1.0/Rakefile b/pkg/bp85-mirror_repos-0.1.0/Rakefile new file mode 100644 index 0000000..02609e3 --- /dev/null +++ b/pkg/bp85-mirror_repos-0.1.0/Rakefile @@ -0,0 +1,32 @@ +require 'puppetlabs_spec_helper/rake_tasks' +require 'puppet-lint/tasks/puppet-lint' +require 'metadata-json-lint/rake_task' + +if RUBY_VERSION >= '1.9' + require 'rubocop/rake_task' + RuboCop::RakeTask.new +end + +PuppetLint.configuration.send('disable_80chars') +PuppetLint.configuration.relative = true +PuppetLint.configuration.ignore_paths = ['spec/**/*.pp', 'pkg/**/*.pp'] + +desc 'Validate manifests, templates, and ruby files' +task :validate do + Dir['manifests/**/*.pp'].each do |manifest| + sh "puppet parser validate --noop #{manifest}" + end + Dir['spec/**/*.rb', 'lib/**/*.rb'].each do |ruby_file| + sh "ruby -c #{ruby_file}" unless ruby_file =~ %r{spec/fixtures} + end + Dir['templates/**/*.erb'].each do |template| + sh "erb -P -x -T '-' #{template} | ruby -c" + end +end + +desc 'Run metadata_lint, lint, validate, and spec tests.' +task :test do + [:metadata_lint, :lint, :validate, :spec].each do |test| + Rake::Task[test].invoke + end +end diff --git a/pkg/bp85-mirror_repos-0.1.0/checksums.json b/pkg/bp85-mirror_repos-0.1.0/checksums.json new file mode 100644 index 0000000..578efd8 --- /dev/null +++ b/pkg/bp85-mirror_repos-0.1.0/checksums.json @@ -0,0 +1,16 @@ +{ + "Gemfile": "36c376f27539ded2a321b2bd432e843b", + "README.md": "746f972d9d2bcad3643cb7ceadf00cb5", + "Rakefile": "f4692851f7e9afcdb02721319e3f18b9", + "examples/init.pp": "ca548733d8c2f76c23e4809be06b1ba0", + "manifests/apache.pp": "8f3524f3abf4781aa39987794149e729", + "manifests/config.pp": "9824a86c6ceca4365fdf45c184604144", + "manifests/init.pp": "0991a1376b6dc4364dac672671879964", + "manifests/install.pp": "9125c5e07e05ff40be9fb138f87e7925", + "manifests/params.pp": "a03bd5b742001576ec8a9a9b3e8b9e9a", + "metadata.json": "42f6115c2a5c930f4a73f6f59656037c", + "spec/classes/init_spec.rb": "7976a6bfe5a87c676034a0d908263e70", + "spec/spec_helper.rb": "0db89c9a486df193c0e40095422e19dc", + "templates/repo.conf.erb": "7bf7da07ba2c294a5496c4090c74247d", + "templates/update-repos.sh.erb": "64734928745e3da11491adfabdd39b5a" +} \ No newline at end of file diff --git a/pkg/bp85-mirror_repos-0.1.0/examples/init.pp b/pkg/bp85-mirror_repos-0.1.0/examples/init.pp new file mode 100644 index 0000000..47f7525 --- /dev/null +++ b/pkg/bp85-mirror_repos-0.1.0/examples/init.pp @@ -0,0 +1,12 @@ +# The baseline for module testing used by Puppet Labs is that each manifest +# should have a corresponding test manifest that declares that class or defined +# type. +# +# Tests are then run by using puppet apply --noop (to check for compilation +# errors and view a log of events) or by fully applying the test in a virtual +# environment (to compare the resulting system state to the desired state). +# +# Learn more about module testing here: +# https://docs.puppet.com/guides/tests_smoke.html +# +include ::mirror_repos diff --git a/pkg/bp85-mirror_repos-0.1.0/manifests/apache.pp b/pkg/bp85-mirror_repos-0.1.0/manifests/apache.pp new file mode 100644 index 0000000..b26da51 --- /dev/null +++ b/pkg/bp85-mirror_repos-0.1.0/manifests/apache.pp @@ -0,0 +1,16 @@ +class mirror_repos::apache { + if $mirror_repos::manage_vhost { + include ::apache + include ::apache::mod::proxy + + if $mirror_repos::vhosts == {} { + apache::vhost { $::fqdn: + port => '80', + docroot => $mirror_repos::repos_dir, + } + } + else { + create_resources('apache::vhost',$mirror_repos::vhosts) + } + } +} diff --git a/pkg/bp85-mirror_repos-0.1.0/manifests/config.pp b/pkg/bp85-mirror_repos-0.1.0/manifests/config.pp new file mode 100644 index 0000000..9b315a8 --- /dev/null +++ b/pkg/bp85-mirror_repos-0.1.0/manifests/config.pp @@ -0,0 +1,34 @@ +# == Class mirror_repos::config +# +# This class is called from mirror_repos +# +class mirror_repos::config { + #just replicate yum.repos.d + file { [ $mirror_repos::config_dir, $mirror_repos::repos_dir ]: + ensure => directory, + } + #create a dir for each OS and then a file for each repo under that OS + $mirror_repos::repos.each |String $os_name , $repos_os | { + $os = regsubst($os_name, '[-]', '_', 'G') + file {"${mirror_repos::config_dir}/${os}.conf": + ensure => 'file', + mode => '0644', + content => template('mirror_repos/repo.conf.erb'), + } + } + $oses = keys($mirror_repos::repos) + #copy file to update repos to localhost + file { '/usr/sbin/update-repos': + ensure => file, + mode => '0755', + content => template('mirror_repos/update-repos.sh.erb'), + } + #run cron every night to update repos + cron { 'update-repos': + command => '/usr/sbin/update-repos', + user => 'root', + hour => 1, + minute => 0, + require => File['/usr/sbin/update-repos'], + } +} diff --git a/pkg/bp85-mirror_repos-0.1.0/manifests/init.pp b/pkg/bp85-mirror_repos-0.1.0/manifests/init.pp new file mode 100644 index 0000000..4ee01d3 --- /dev/null +++ b/pkg/bp85-mirror_repos-0.1.0/manifests/init.pp @@ -0,0 +1,49 @@ +# Class: mirror_repos +# =========================== +# +# Full description of class mirror_repos here. +# +# Parameters +# ---------- +# +# * `mirror_repos::vhost` +# create apache vhost with this name. Default is FQDN +# +# Variables +# ---------- +# +# * `mirror_repos::config_dir` +# Where to deploy the repo configuration files. +# Default is `/etc/mirror.repos.d` +# +# * `mirror_repos::repos_dir` +# Where to store the mirrorred repos +# Default is `/repos` +# +# * `mirror_repos::repos` +# repositories to mirror +# Default is empty +# +# Examples +# #### +# -------- +# +# @example +# class { 'mirror_repos': +# config_dir => '/etc/repos_conf', +# } +# +# +class mirror_repos ( + Array $packages = $mirror_repos::params::packages, + Hash $repos = $mirror_repos::params::repos, + Hash $vhosts = $mirror_repos::params::vhosts, + String $config_dir = $mirror_repos::params::config_dir, + String $repos_dir = $mirror_repos::params::repos_dir, + Boolean $manage_vhost = $mirror_repos::params::manage_vhost, + ) inherits mirror_repos::params { + + class { '::mirror_repos::install': } + -> class { '::mirror_repos::config': } + -> class { '::mirror_repos::apache': } +} diff --git a/pkg/bp85-mirror_repos-0.1.0/manifests/install.pp b/pkg/bp85-mirror_repos-0.1.0/manifests/install.pp new file mode 100644 index 0000000..35c26bc --- /dev/null +++ b/pkg/bp85-mirror_repos-0.1.0/manifests/install.pp @@ -0,0 +1,5 @@ +class mirror_repos::install { + package { $mirror_repos::packages: + ensure => present, + } +} diff --git a/pkg/bp85-mirror_repos-0.1.0/manifests/params.pp b/pkg/bp85-mirror_repos-0.1.0/manifests/params.pp new file mode 100644 index 0000000..4d48ab8 --- /dev/null +++ b/pkg/bp85-mirror_repos-0.1.0/manifests/params.pp @@ -0,0 +1,15 @@ +class mirror_repos::params { + case $::osfamily { + 'RedHat': { + $packages = ['createrepo', 'yum-utils'] + $manage_vhost = true + $vhosts = {} + $config_dir = '/etc/mirror.repos.d' + $repos_dir = '/repos' + $repos = {} + } + default: { + fail("${::operatingsystem} not supported") + } + } +} diff --git a/pkg/bp85-mirror_repos-0.1.0/metadata.json b/pkg/bp85-mirror_repos-0.1.0/metadata.json new file mode 100644 index 0000000..752c3fd --- /dev/null +++ b/pkg/bp85-mirror_repos-0.1.0/metadata.json @@ -0,0 +1,15 @@ +{ + "name": "bp85-mirror_repos", + "version": "0.1.0", + "author": "bp85", + "summary": "Mirror yum repositories to local + and create yum repos from those", + "license": "Apache-2.0", + "source": "https://github.com/bp85/puppet-mirror_repos", + "project_page": "https://github.com/bp85/puppet-mirror_repos", + "issues_url": "https://github.com/bp85/puppet-mirror_repos/issues", + "dependencies": [ + {"name":"puppetlabs-stdlib","version_requirement":">= 1.0.0"}, + {"name":"puppetlabs-apache","version_requirement":">=1.11.0"} + ], + "data_provider": null +} diff --git a/pkg/bp85-mirror_repos-0.1.0/spec/classes/init_spec.rb b/pkg/bp85-mirror_repos-0.1.0/spec/classes/init_spec.rb new file mode 100644 index 0000000..6d70921 --- /dev/null +++ b/pkg/bp85-mirror_repos-0.1.0/spec/classes/init_spec.rb @@ -0,0 +1,6 @@ +require 'spec_helper' +describe 'mirror_repos' do + context 'with default values for all parameters' do + it { should contain_class('mirror_repos') } + end +end diff --git a/pkg/bp85-mirror_repos-0.1.0/spec/spec_helper.rb b/pkg/bp85-mirror_repos-0.1.0/spec/spec_helper.rb new file mode 100644 index 0000000..2c6f566 --- /dev/null +++ b/pkg/bp85-mirror_repos-0.1.0/spec/spec_helper.rb @@ -0,0 +1 @@ +require 'puppetlabs_spec_helper/module_spec_helper' diff --git a/pkg/bp85-mirror_repos-0.1.0/templates/repo.conf.erb b/pkg/bp85-mirror_repos-0.1.0/templates/repo.conf.erb new file mode 100644 index 0000000..d5d4990 --- /dev/null +++ b/pkg/bp85-mirror_repos-0.1.0/templates/repo.conf.erb @@ -0,0 +1,27 @@ +[main] +cachedir=/var/cache/yum/<%= @os.split(/(\d+)/)[0] %>/<%= @os.split(/(\d+)/)[1] %> +keepcache=0 +debuglevel=2 +logfile=/var/log/yum.log +exactarch=1 +obsoletes=1 +gpgcheck=1 +plugins=1 + +<% @repos_os.each do |repo, info | -%> +[<%= repo %>] +name=<%= @os.split("-")[0] %> - <%= repo %> +<% if info.has_key?('baseurl') -%> +baseurl=<%= info['baseurl'] %> +<% end -%> +<% if info.has_key?('enabled') -%> +enabled=<%= info['enabled'] %> +<% end -%> +<% if info.has_key?('gpgkey') -%> +gpgcheck=1 +gpgkey=<%= info['gpgkey'] %> +<% else -%> +gpgcheck=0 +<% end -%> + +<% end -%> diff --git a/pkg/bp85-mirror_repos-0.1.0/templates/update-repos.sh.erb b/pkg/bp85-mirror_repos-0.1.0/templates/update-repos.sh.erb new file mode 100644 index 0000000..80080f1 --- /dev/null +++ b/pkg/bp85-mirror_repos-0.1.0/templates/update-repos.sh.erb @@ -0,0 +1,117 @@ +#!/bin/bash +# Author: Bhanu Prasad G (gangurubhanu@gmail.com) + +# This file is managed by puppet + +exec 3>&1 +exec 4>&2 + +#default variables +: ${UPDATE:=True} +: ${VERBOSE:=False} + +#define variables +REPOS_DIR=<%= scope.lookupvar('mirror_repos::repos_dir') %> +CONFIG_DIR=<%= scope.lookupvar('mirror_repos::config_dir') %> +CREATEREPO_CMD=`which createrepo` +REPOSYNC_CMD="$(which reposync) -q" + +show_help(){ + +cat << EOF 1>&2 + +USAGE: $0 [-huv] [-o OS] [-r REPO1,REPO2] -- Script to mirror repositories to local repos + +where: + -h | --help show help on how to run this script + -o | --os update this OS repos only (default all) + -r | --repo repo name to update (all by default) + -v | --verbose show output/error to stdout/stderr (redirect to /dev/null by default) + -u | --update repos update only (enabled by default) + +By default, running this script sync all available repositories for all OS. +For syncing only a single/few repos give reponames with -r option seperated by commas. + +EOF + +} + +#make options based on help +OPTIONS=$(getopt -o "vuho:r:" -l "verbose,update,help,os:,repo:" -n 'update-repos' -- "$@") +[ $? -eq 0 ] && eval set -- "$OPTIONS" + + +main(){ + if [ ${UPDATE} == 'True' ]; then + [ ! -f $CONFIG_DIR/$OS.conf ] && echo "$OS configuration not available at $CONFIG_DIR" && exit 1 + for REPO in ${REPOS_OS[@]}; do + if ! egrep -s "\[$REPO\]" $CONFIG_DIR/$OS.conf >& /dev/null ; then + echo "$REPO configuration not available" && exit 1 + fi + echo "updating $REPO for $OS now" + yum clean all >& /dev/null + #sync remote repos to local directories + + $REPOSYNC_CMD -q -l -c $CONFIG_DIR/$OS.conf --repoid=$REPO --download_path=$REPOS_DIR/$OS/ + #create yum repository from local synced directories + $CREATEREPO_CMD --workers=8 --update $REPOS_DIR/$OS/$REPO + done + #reset REPOS for next OS + REPOS_OS='' + fi +} + +while true; do + case "$1" in + -h | --help) + show_help + exit 1 + ;; + -o | --os) + OSES=$2 + shift 2 + ;; + -r | --repo) + REPOS=$2 + shift 2 + ;; + -v | --verbose) + CREATEREPO_CMD+=' -v' + VERBOSE='True' + REPOSYNC_CMD=`which reposync` + shift + ;; + -u | --update) + shift + ;; + --) + shift + break + ;; + *) + echo "Option not found" + show_help + exit 1 + ;; + esac +done + +#if no os, is given get all OS defined in puppet hiera +[ $OSES ] || OSES=( <%= @oses.join(" ") %> ) + +for OS in ${OSES[@]}; do + #if repos are specified, make them an array + ##if repos are not specified, get from configs + <% @oses.each do | os | -%> + [ $REPOS ] && REPOS_<%= os.split('-').join('_') %>=( $(echo "$REPOS" |sed 's/,/ /g') ) + [ ${REPOS_<%= os.split('-').join('_') %>} ] || REPOS_<%= os.split('-').join('_') %>=( <%= scope.lookupvar('mirror_repos::repos')[os].keys.join(" ") %> ) + <% end -%> + OS=$(echo $OS | sed 's/-/_/') + #now define a new array, because substrings won't perform well in for loop + REPOS_OS=$(eval echo \${REPOS_${OS}[*]}) + if [ ${VERBOSE} == 'False' ]; then + exec 2>/dev/null 1>/dev/null + fi + #call main function always + main +done diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb new file mode 100644 index 0000000..6d70921 --- /dev/null +++ b/spec/classes/init_spec.rb @@ -0,0 +1,6 @@ +require 'spec_helper' +describe 'mirror_repos' do + context 'with default values for all parameters' do + it { should contain_class('mirror_repos') } + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..2c6f566 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1 @@ +require 'puppetlabs_spec_helper/module_spec_helper' diff --git a/templates/repo.conf.erb b/templates/repo.conf.erb new file mode 100644 index 0000000..d5d4990 --- /dev/null +++ b/templates/repo.conf.erb @@ -0,0 +1,27 @@ +[main] +cachedir=/var/cache/yum/<%= @os.split(/(\d+)/)[0] %>/<%= @os.split(/(\d+)/)[1] %> +keepcache=0 +debuglevel=2 +logfile=/var/log/yum.log +exactarch=1 +obsoletes=1 +gpgcheck=1 +plugins=1 + +<% @repos_os.each do |repo, info | -%> +[<%= repo %>] +name=<%= @os.split("-")[0] %> - <%= repo %> +<% if info.has_key?('baseurl') -%> +baseurl=<%= info['baseurl'] %> +<% end -%> +<% if info.has_key?('enabled') -%> +enabled=<%= info['enabled'] %> +<% end -%> +<% if info.has_key?('gpgkey') -%> +gpgcheck=1 +gpgkey=<%= info['gpgkey'] %> +<% else -%> +gpgcheck=0 +<% end -%> + +<% end -%> diff --git a/templates/update-repos.sh.erb b/templates/update-repos.sh.erb new file mode 100644 index 0000000..80080f1 --- /dev/null +++ b/templates/update-repos.sh.erb @@ -0,0 +1,117 @@ +#!/bin/bash +# Author: Bhanu Prasad G (gangurubhanu@gmail.com) + +# This file is managed by puppet + +exec 3>&1 +exec 4>&2 + +#default variables +: ${UPDATE:=True} +: ${VERBOSE:=False} + +#define variables +REPOS_DIR=<%= scope.lookupvar('mirror_repos::repos_dir') %> +CONFIG_DIR=<%= scope.lookupvar('mirror_repos::config_dir') %> +CREATEREPO_CMD=`which createrepo` +REPOSYNC_CMD="$(which reposync) -q" + +show_help(){ + +cat << EOF 1>&2 + +USAGE: $0 [-huv] [-o OS] [-r REPO1,REPO2] -- Script to mirror repositories to local repos + +where: + -h | --help show help on how to run this script + -o | --os update this OS repos only (default all) + -r | --repo repo name to update (all by default) + -v | --verbose show output/error to stdout/stderr (redirect to /dev/null by default) + -u | --update repos update only (enabled by default) + +By default, running this script sync all available repositories for all OS. +For syncing only a single/few repos give reponames with -r option seperated by commas. + +EOF + +} + +#make options based on help +OPTIONS=$(getopt -o "vuho:r:" -l "verbose,update,help,os:,repo:" -n 'update-repos' -- "$@") +[ $? -eq 0 ] && eval set -- "$OPTIONS" + + +main(){ + if [ ${UPDATE} == 'True' ]; then + [ ! -f $CONFIG_DIR/$OS.conf ] && echo "$OS configuration not available at $CONFIG_DIR" && exit 1 + for REPO in ${REPOS_OS[@]}; do + if ! egrep -s "\[$REPO\]" $CONFIG_DIR/$OS.conf >& /dev/null ; then + echo "$REPO configuration not available" && exit 1 + fi + echo "updating $REPO for $OS now" + yum clean all >& /dev/null + #sync remote repos to local directories + + $REPOSYNC_CMD -q -l -c $CONFIG_DIR/$OS.conf --repoid=$REPO --download_path=$REPOS_DIR/$OS/ + #create yum repository from local synced directories + $CREATEREPO_CMD --workers=8 --update $REPOS_DIR/$OS/$REPO + done + #reset REPOS for next OS + REPOS_OS='' + fi +} + +while true; do + case "$1" in + -h | --help) + show_help + exit 1 + ;; + -o | --os) + OSES=$2 + shift 2 + ;; + -r | --repo) + REPOS=$2 + shift 2 + ;; + -v | --verbose) + CREATEREPO_CMD+=' -v' + VERBOSE='True' + REPOSYNC_CMD=`which reposync` + shift + ;; + -u | --update) + shift + ;; + --) + shift + break + ;; + *) + echo "Option not found" + show_help + exit 1 + ;; + esac +done + +#if no os, is given get all OS defined in puppet hiera +[ $OSES ] || OSES=( <%= @oses.join(" ") %> ) + +for OS in ${OSES[@]}; do + #if repos are specified, make them an array + ##if repos are not specified, get from configs + <% @oses.each do | os | -%> + [ $REPOS ] && REPOS_<%= os.split('-').join('_') %>=( $(echo "$REPOS" |sed 's/,/ /g') ) + [ ${REPOS_<%= os.split('-').join('_') %>} ] || REPOS_<%= os.split('-').join('_') %>=( <%= scope.lookupvar('mirror_repos::repos')[os].keys.join(" ") %> ) + <% end -%> + OS=$(echo $OS | sed 's/-/_/') + #now define a new array, because substrings won't perform well in for loop + REPOS_OS=$(eval echo \${REPOS_${OS}[*]}) + if [ ${VERBOSE} == 'False' ]; then + exec 2>/dev/null 1>/dev/null + fi + #call main function always + main +done