Skip to content

Commit a606525

Browse files
committed
First module
0 parents  commit a606525

30 files changed

+1008
-0
lines changed

Gemfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
source ENV['GEM_SOURCE'] || 'https://rubygems.org'
2+
3+
puppetversion = ENV.key?('PUPPET_VERSION') ? ENV['PUPPET_VERSION'] : ['>= 3.3']
4+
gem 'metadata-json-lint'
5+
gem 'puppet', puppetversion
6+
gem 'puppetlabs_spec_helper', '>= 1.0.0'
7+
gem 'puppet-lint', '>= 1.0.0'
8+
gem 'facter', '>= 1.7.0'
9+
gem 'rspec-puppet'
10+
11+
# rspec must be v2 for ruby 1.8.7
12+
if RUBY_VERSION >= '1.8.7' && RUBY_VERSION < '1.9'
13+
gem 'rspec', '~> 2.0'
14+
gem 'rake', '~> 10.0'
15+
else
16+
# rubocop requires ruby >= 1.9
17+
gem 'rubocop'
18+
end

README.md

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# mirror_repos
2+
3+
#### Table of Contents
4+
5+
1. [Description](#description)
6+
2. [Setup - The basics of getting started with mirror_repos](#setup)
7+
* [Beginning with mirror_repos](#beginning-with-mirror_repos)
8+
3. [Usage - Configuration options and additional functionality](#examples)
9+
4. [Reference - An under-the-hood peek at what the module is doing and how](#reference)
10+
5. [Limitations - OS compatibility, etc.](#limitations)
11+
6. [Development - Guide for contributing to the module](#development)
12+
13+
## Description
14+
15+
`puppetlabs-apache` module if you want to manage vhost within this module.
16+
apache module create a http proxy with fqdn of the hostname.
17+
18+
This module copy all available rpms from given repo_source using reposync and
19+
then create repository using createrepo from all rpms.
20+
21+
## Setup
22+
23+
Repo configuration should be a Hash in following format
24+
`mirror_repos::repos:` must be followed by `OS-ARCH` and then
25+
name of the repo and configuration of repo
26+
27+
### Beginning with mirror_repos
28+
29+
This module copy a bash script `update-repos` to /usr/sbin.
30+
This script runs every night to sync remote repos.
31+
This script has many options, to know more do `/usr/sbin/update-repos -h`.
32+
33+
#### Examples
34+
35+
#####
36+
37+
It is highly recommended to define repos in Hiera.
38+
```
39+
mirror_repos::config_dir: '/etc/repos'
40+
mirror_repos::repos_dir: '/n/repos'
41+
mirror_repos::repos:
42+
centos7-x86_64:
43+
base:
44+
baseurl: 'http://mirrors.tripadvisor.com/centos/7/os/x86_64/'
45+
gpgkey: 'http://mirrors.tripadvisor.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7'
46+
enabled: 1
47+
centos6-x86_64:
48+
base:
49+
baseurl: 'http://mirror.centos.org/centos-6/6/os/x86_64/'
50+
enabled: 0
51+
```
52+
53+
## Reference
54+
55+
#### Parameters
56+
57+
The following parameters are available in the `mirror_repos` class.
58+
59+
##### `packages`
60+
61+
Data type: `Array`
62+
63+
64+
65+
Default value: $mirror_repos::params::packages
66+
67+
##### `repos`
68+
69+
Data type: `Hash`
70+
71+
72+
73+
Default value: $mirror_repos::params::repos
74+
75+
##### `vhosts`
76+
77+
Data type: `Hash`
78+
79+
80+
Default value: $mirror_repos::params::vhosts
81+
82+
##### `config_dir`
83+
84+
Data type: `String`
85+
86+
87+
Default value: $mirror_repos::params::config_dir
88+
89+
##### `repos_dir`
90+
91+
Data type: `String`
92+
93+
94+
Default value: $mirror_repos::params::repos_dir
95+
96+
##### `manage_vhost`
97+
98+
Data type: `Boolean`
99+
100+
101+
Default value: $mirror_repos::params::manage_vhost
102+
103+
104+
### mirror_repos::apache
105+
106+
The mirror_repos::apache class.
107+
108+
### mirror_repos::config
109+
110+
== Class mirror_repos::config
111+
112+
This class is called from mirror_repos
113+
114+
### mirror_repos::install
115+
116+
The mirror_repos::install class.
117+
118+
### mirror_repos::params
119+
120+
The mirror_repos::params class.
121+
122+
## Limitations
123+
124+
This Module is tested on RedHat7 and CentOS7.
125+
126+
## Development
127+
128+
For contributing Fork this module and open PR.
129+
130+
Authors
131+
-------
132+
133+
Bhanu Prasad G <[email protected]>
134+
135+
Copyright
136+
---------
137+
Copyright [2018] [Bhanu Prasad G]
138+
139+
Licensed under the Apache License, Version 2.0 (the "License");
140+
you may not use this file except in compliance with the License.
141+
You may obtain a copy of the License at
142+
143+
http://www.apache.org/licenses/LICENSE-2.0
144+
145+
Unless required by applicable law or agreed to in writing, software
146+
distributed under the License is distributed on an "AS IS" BASIS,
147+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
148+
See the License for the specific language governing permissions and
149+
limitations under the License.

Rakefile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require 'puppetlabs_spec_helper/rake_tasks'
2+
require 'puppet-lint/tasks/puppet-lint'
3+
require 'metadata-json-lint/rake_task'
4+
5+
if RUBY_VERSION >= '1.9'
6+
require 'rubocop/rake_task'
7+
RuboCop::RakeTask.new
8+
end
9+
10+
PuppetLint.configuration.send('disable_80chars')
11+
PuppetLint.configuration.relative = true
12+
PuppetLint.configuration.ignore_paths = ['spec/**/*.pp', 'pkg/**/*.pp']
13+
14+
desc 'Validate manifests, templates, and ruby files'
15+
task :validate do
16+
Dir['manifests/**/*.pp'].each do |manifest|
17+
sh "puppet parser validate --noop #{manifest}"
18+
end
19+
Dir['spec/**/*.rb', 'lib/**/*.rb'].each do |ruby_file|
20+
sh "ruby -c #{ruby_file}" unless ruby_file =~ %r{spec/fixtures}
21+
end
22+
Dir['templates/**/*.erb'].each do |template|
23+
sh "erb -P -x -T '-' #{template} | ruby -c"
24+
end
25+
end
26+
27+
desc 'Run metadata_lint, lint, validate, and spec tests.'
28+
task :test do
29+
[:metadata_lint, :lint, :validate, :spec].each do |test|
30+
Rake::Task[test].invoke
31+
end
32+
end

examples/init.pp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# The baseline for module testing used by Puppet Labs is that each manifest
2+
# should have a corresponding test manifest that declares that class or defined
3+
# type.
4+
#
5+
# Tests are then run by using puppet apply --noop (to check for compilation
6+
# errors and view a log of events) or by fully applying the test in a virtual
7+
# environment (to compare the resulting system state to the desired state).
8+
#
9+
# Learn more about module testing here:
10+
# https://docs.puppet.com/guides/tests_smoke.html
11+
#
12+
include ::mirror_repos

manifests/apache.pp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class mirror_repos::apache {
2+
if $mirror_repos::manage_vhost {
3+
include ::apache
4+
include ::apache::mod::proxy
5+
6+
if $mirror_repos::vhosts == {} {
7+
apache::vhost { $::fqdn:
8+
port => '80',
9+
docroot => $mirror_repos::repos_dir,
10+
}
11+
}
12+
else {
13+
create_resources('apache::vhost',$mirror_repos::vhosts)
14+
}
15+
}
16+
}

manifests/config.pp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# == Class mirror_repos::config
2+
#
3+
# This class is called from mirror_repos
4+
#
5+
class mirror_repos::config {
6+
#just replicate yum.repos.d
7+
file { [ $mirror_repos::config_dir, $mirror_repos::repos_dir ]:
8+
ensure => directory,
9+
}
10+
#create a dir for each OS and then a file for each repo under that OS
11+
$mirror_repos::repos.each |String $os_name , $repos_os | {
12+
$os = regsubst($os_name, '[-]', '_', 'G')
13+
file {"${mirror_repos::config_dir}/${os}.conf":
14+
ensure => 'file',
15+
mode => '0644',
16+
content => template('mirror_repos/repo.conf.erb'),
17+
}
18+
}
19+
$oses = keys($mirror_repos::repos)
20+
#copy file to update repos to localhost
21+
file { '/usr/sbin/update-repos':
22+
ensure => file,
23+
mode => '0755',
24+
content => template('mirror_repos/update-repos.sh.erb'),
25+
}
26+
#run cron every night to update repos
27+
cron { 'update-repos':
28+
command => '/usr/sbin/update-repos',
29+
user => 'root',
30+
hour => 1,
31+
minute => 0,
32+
require => File['/usr/sbin/update-repos'],
33+
}
34+
}

manifests/init.pp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Class: mirror_repos
2+
# ===========================
3+
#
4+
# Full description of class mirror_repos here.
5+
#
6+
# Parameters
7+
# ----------
8+
#
9+
# * `mirror_repos::vhost`
10+
# create apache vhost with this name. Default is FQDN
11+
#
12+
# Variables
13+
# ----------
14+
#
15+
# * `mirror_repos::config_dir`
16+
# Where to deploy the repo configuration files.
17+
# Default is `/etc/mirror.repos.d`
18+
#
19+
# * `mirror_repos::repos_dir`
20+
# Where to store the mirrorred repos
21+
# Default is `/repos`
22+
#
23+
# * `mirror_repos::repos`
24+
# repositories to mirror
25+
# Default is empty
26+
#
27+
# Examples
28+
# ####
29+
# --------
30+
#
31+
# @example
32+
# class { 'mirror_repos':
33+
# config_dir => '/etc/repos_conf',
34+
# }
35+
#
36+
#
37+
class mirror_repos (
38+
Array $packages = $mirror_repos::params::packages,
39+
Hash $repos = $mirror_repos::params::repos,
40+
Hash $vhosts = $mirror_repos::params::vhosts,
41+
String $config_dir = $mirror_repos::params::config_dir,
42+
String $repos_dir = $mirror_repos::params::repos_dir,
43+
Boolean $manage_vhost = $mirror_repos::params::manage_vhost,
44+
) inherits mirror_repos::params {
45+
46+
class { '::mirror_repos::install': }
47+
-> class { '::mirror_repos::config': }
48+
-> class { '::mirror_repos::apache': }
49+
}

manifests/install.pp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class mirror_repos::install {
2+
package { $mirror_repos::packages:
3+
ensure => present,
4+
}
5+
}

manifests/params.pp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class mirror_repos::params {
2+
case $::osfamily {
3+
'RedHat': {
4+
$packages = ['createrepo', 'yum-utils']
5+
$manage_vhost = true
6+
$vhosts = {}
7+
$config_dir = '/etc/mirror.repos.d'
8+
$repos_dir = '/repos'
9+
$repos = {}
10+
}
11+
default: {
12+
fail("${::operatingsystem} not supported")
13+
}
14+
}
15+
}

metadata.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "bp85-mirror_repos",
3+
"version": "0.1.0",
4+
"author": "bp85",
5+
"summary": "Mirror yum repositories to local + and create yum repos from those",
6+
"license": "Apache-2.0",
7+
"source": "https://github.com/bp85/puppet-mirror_repos",
8+
"project_page": "https://github.com/bp85/puppet-mirror_repos",
9+
"issues_url": "https://github.com/bp85/puppet-mirror_repos/issues",
10+
"dependencies": [
11+
{"name":"puppetlabs-stdlib","version_requirement":">= 1.0.0"},
12+
{"name":"puppetlabs-apache","version_requirement":">=1.11.0"}
13+
],
14+
"data_provider": null
15+
}

0 commit comments

Comments
 (0)