yumrepo_server/ 0000775 0001750 0001750 00000000000 12317557624 013376 5 ustar morrm1 morrm1 yumrepo_server/Gemfile 0000664 0001750 0001750 00000000273 12317433775 014673 0 ustar morrm1 morrm1 source 'https://rubygems.org'
group :test do
gem 'chefspec', '~> 3.3'
gem 'foodcritic'
gem 'strainer'
gem 'chef', '~> 11.0'
gem 'knife-spork'
gem 'rake'
gem 'rubocop'
end
yumrepo_server/providers/ 0000775 0001750 0001750 00000000000 12317556034 015405 5 ustar morrm1 morrm1 yumrepo_server/providers/default.rb 0000664 0001750 0001750 00000004722 12317554677 017376 0 ustar morrm1 morrm1 require 'tempfile'
# Support whyrun
def whyrun_supported?
true
end
action :create do
cmd = 'createrepo' << shell_sanitize(@new_resource.options)
dir = resolve_full_path(@new_resource.dir)
pkgs = @new_resource.packages
src = @new_resource.remote_source
directory dir do
action :create
recursive true
end
pkg_file = create_pkg_file(pkgs) unless pkgs.nil? || pkgs.empty?
begin
converge_by "Creating repo at #{dir}" do
unless pkgs.nil? || pkgs.empty?
cmd = cmd << " -i #{pkg_file.path}"
download_pkgs(src, dir, pkgs) if src
end
Chef::Log.debug "Creating repo #{dir} with command #{cmd}"
execute 'create yum repo' do
action :run
command cmd << " #{dir}"
end
end
ensure
file pkg_file.path do
action :delete
only_if { pkg_file }
end
end
end
action :delete do
dir = resolve_full_path(@new_resource.dir)
if ::Dir.exist?(::File.join(dir, 'repodata'))
converge_by "Delete repo dir #{dir}" do
Chef::Log.debug "Deleting repo at #{dir}"
directory dir do
action :delete
recursive true
end
end
else
Chef::Log.warn "#{dir} does not appear to be a repository directory, will not delete"
end
end
action :update do
dir = resolve_full_path(@new_resource.dir)
opts = shell_sanitize(@new_resource.options)
if ::Dir.exist?(::File.join(dir, 'repodata'))
converge_by "Updating repo dir #{dir}" do
cmd = "createrepo --update #{opts}"
Chef::Log.debug "Updating repo at #{dir} with command #{cmd}"
execute 'update yum repo' do
action :run
command cmd << " #{dir}"
end
end
else
Chef::Log.warn "#{dir} does not appear to be a repository directory, will not update"
end
end
def download_pkgs(src, dir, pkgs)
pkgs.each do |p|
url = src + "/#{p}"
dst = ::File.join(dir, p)
Chef::Log.debug "Downloading from #{url} to #{dst}"
remote_file dst do
action :create
backup false
source url
end
end
end
def create_pkg_file(pkg_ary)
unless pkg_ary.nil? || pkg_ary.empty?
f = Tempfile.new('yum_pkg_list')
begin
f.write(pkg_ary.join("\n"))
ensure
f.close(false)
end
f
end
end
def resolve_full_path(res_dir)
base_dir = node['yum']['server']['repo_base_dir']
dir = ::File.join(base_dir, res_dir)
dir = res_dir if res_dir.start_with?(base_dir)
dir
end
def shell_sanitize(str)
str ? str.strip.shellescape : ''
end
yumrepo_server/Rakefile 0000664 0001750 0001750 00000004274 12317433521 015037 0 ustar morrm1 morrm1 cb_dir = ::File.dirname(__FILE__)
cb_name = ::File.basename(cb_dir)
task :clean do |t|
::Dir.chdir(cb_dir)
::File.unlink('metadata.json') if ::File.exists?('metadata.json')
::Dir.glob('*.lock').each do |f|
::File.unlink(f)
end
end
task :distclean => [:clean] do |t|
::Dir.chdir(cb_dir)
file = ::File.join('..', "#{cb_name}.tar")
::File.unlink(file) if ::File.exists? file
end
task :knife_test do |t|
sh "bundle exec knife cookbook test #{cb_name}"
end
task :fc => [:foodcritic]
task :foodcritic do |t|
sh "bundle exec foodcritic #{cb_dir}"
end
task :rc => [:rubocop]
task :rubocop do |t|
sh "bundle exec rubocop #{cb_dir}"
end
task :chefspec do |t|
::Dir.chdir(cb_dir)
sh 'bundle exec rspec --color --format documentation'
end
task :test do |t|
if ::File.exists?(::File.join(cb_dir, 'Strainerfile'))
sh 'bundle exec strainer test' if ::File.exists?(::File.join(cb_dir, 'Strainerfile'))
else
Rake::Task[:knife_test].execute
Rake::Task[:foodcritic].execute
Rake::Task[:rubocop].execute
Rake::Task[:chefspec].execute
end
end
task :release, [:type] => [:clean, :test] do |t, args|
type = args.type
if type.nil? || type.strip.empty?
print "\nEnter release type (major|minor|patch (default)|manual): "
type = STDIN.gets.chomp
end
type = 'patch' if type.nil? || type.strip.empty?
if type.start_with? 'manual'
ary = type.split(/\s+/)
if ary.size != 2
print 'ERROR: manual release type requires a version (ex. manual 1.2.3)\n'
exit 1
elsif !ary[1].strip.match(/^\d+\.\d+\.\d+$/)
print 'ERROR: version format must be in the form of x.y.z\n'
exit 1
end
elsif type.strip.match(/^\d+\.\d+\.\d+$/)
type = "manual #{type}"
else
unless type.start_with?('major') || type.start_with?('minor') || type.start_with?('patch')
print "ERROR: invalid release type of #{type} given\n"
exit 1
end
end
sh 'bundle exec berks install'
sh "bundle exec knife spork bump #{cb_name} #{type}"
end
task :bundle => [:release] do |t|
sh "bundle exec knife cookbook metadata #{cb_name}"
::Dir.chdir(::File.join(cb_dir, '..'))
sh "tar --exclude-backups --exclude-vcs -cvf #{cb_name}.tar #{cb_name}"
end
yumrepo_server/metadata.rb 0000664 0001750 0001750 00000000546 12317557623 015507 0 ustar morrm1 morrm1 name 'yumrepo_server'
maintainer 'Michael Morris'
maintainer_email 'michael.m.morris@gmail.com'
license '3-clause BSD'
description 'Installs/Configures Yum repository server'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '0.1.0'
%w(redhat centos fedora).each do |p|
supports p
end
depends 'apache2'
depends 'logrotate'
yumrepo_server/Berksfile.lock 0000664 0001750 0001750 00000000271 12317557621 016153 0 ustar morrm1 morrm1 {
"sources": {
"yumrepo_server": {
"path": "."
},
"apache2": {
"locked_version": "1.7.0"
},
"logrotate": {
"locked_version": "1.5.0"
}
}
}
yumrepo_server/chefignore 0000664 0001750 0001750 00000001731 12317433471 015425 0 ustar morrm1 morrm1 # Put files/directories that should be ignored in this file when uploading
# or sharing to the community site.
# Lines that start with '# ' are comments.
# OS generated files #
######################
.DS_Store
Icon?
nohup.out
ehthumbs.db
Thumbs.db
# SASS #
########
.sass-cache
# EDITORS #
###########
\#*
.#*
*~
*.sw[a-z]
*.bak
REVISION
TAGS*
tmtags
*_flymake.*
*_flymake
*.tmproj
.project
.settings
mkmf.log
## COMPILED ##
##############
a.out
*.o
*.pyc
*.so
*.com
*.class
*.dll
*.exe
*/rdoc/
# Testing #
###########
.watchr
.rspec
spec/*
spec/fixtures/*
test/*
features/*
Guardfile
Procfile
# SCM #
#######
.git
*/.git
.gitignore
.gitmodules
.gitconfig
.gitattributes
.svn
*/.bzr/*
*/.hg/*
*/.svn/*
# Berkshelf #
#############
Berksfile
Berksfile.lock
cookbooks/*
tmp
# Cookbooks #
#############
CONTRIBUTING
CHANGELOG*
# Strainer #
############
Colanderfile
Strainerfile
.colander
.strainer
# Vagrant #
###########
.vagrant
Vagrantfile
# Travis #
##########
.travis.yml
yumrepo_server/resources/ 0000775 0001750 0001750 00000000000 12317546326 015405 5 ustar morrm1 morrm1 yumrepo_server/resources/default.rb 0000664 0001750 0001750 00000001207 12317546326 017356 0 ustar morrm1 morrm1 actions :create, :delete, :update
default_action :create
# Directory to create under node['yum']['server']['repo_base_dir']
attribute :dir, kind_of: String, name_attribute: true, required: true
# Options to pass to createrepo/modifyrepo cmd
attribute :options, kind_of: String
# Array of RPM package file names to retrieve from :remote_source,
# or to pass to createrepo cmd.
# Must be supplied with :remote_source option, otherwise optional,
# and defaults to all pkgs under :dir
attribute :packages, kind_of: Array
# URL of source to retrieve pkgs from
# (protocol must be supported by remote_file resource)
attribute :remote_source, String
yumrepo_server/Berksfile 0000664 0001750 0001750 00000000050 12317354572 015217 0 ustar morrm1 morrm1 chef_api :config
site :opscode
metadata
yumrepo_server/metadata.json 0000664 0001750 0001750 00000007411 12317557624 016054 0 ustar morrm1 morrm1 {"name":"yumrepo_server","description":"Installs/Configures Yum repository server","long_description":"yumrepo_server Cookbook\n========================\nThis cookbook configures a Yum repository to be served from your system. It will automatically install and configure the Apache web server (as it's the only server that's available without requiring the EPEL yum repo). It also install the createrepo package for the utilities needed to setup a directory as a yum source.\n\nRequirements\n------------\n\n#### cookbooks\n- `apache2`\n- `logrotate`\n\n#### packages\n- `httpd` - needed to serve the packages in the repository\n- `createrepo` - needed to setup the repository\n- `logrotate` - needed by the httpd package to configure log file management\n\n#### platforms\nAny system that uses Yum and has the required pakcages\n\nAttributes\n----------\n\n#### yumrepo_server::default\n\n* **['yum']['server']['repo\\_base\\_dir']** \n _Type:_ String \n _Description:_ The base directory where the repositories will be configured. Will be used as Apache's DocumentRoot \n _Default:_ /var/lib/yum-repo \n\n* **['apache']['include\\_logrotate']** \n _Type:_ Boolean \n _Description:_ Flag to determine if logrotate will be configured for Apache logs \n _Default:_ true\n\nUsage\n-----\n### Recipes\n\n#### yumrepo_server::default\n\nJust include `yumrepo_server` in your node's `run_list`:\n\n```json\n{\n \"name\":\"my_node\",\n \"run_list\": [\n \"recipe[yumrepo_server]\"\n ]\n}\n```\n\n### LWRPs\n\n#### yumrepo_server\n\n##### :create action\n\nCreate a yum repository inside of the relative path given (will be rooted at node['yum']['server']['repo_base_dir'])\n\n_With implied directory_\n\n```ruby\nyumrepo_server 'relative/yum/repo/path' do\n action :create\n options \"-v --quiet\" # An optional string of options to pass to the createrepo command\n remote_source \"http://upstream.com/path\" # An optional URL string used as a base to retrieve packages from\n packages %w(pkg1.rpm pkg2.rpm pkg3.rpm) # An optional array of package names to be configured in the repo (default is all packages). Required with the :remote_source attribute to specify which packages to retrieve.\nend\n```\n\n_With explicit directory_\n\n```ruby\nyumrepo_server 'creates my yum repo' do\n action :create\n dir 'relative/yum/repo/path' # Required relative path to create repo at (this value will be appended to the value of node['yum']['server']['repo_base_dir'])\n options \"-v --quiet\" # An optional string of options to pass to the createrepo command\n remote_source \"http://upstream.com/path\" # An optional URL string used as a base to retrieve packages from\n packages %w(pkg1.rpm pkg2.rpm pkg3.rpm) # An optional array of package names to be configured in the repo (default is all packages). Required with the :remote_source attribute to specify which packages to retrieve.\nend\n```\n\n##### :update action\n\nUpdate the the yum repository at the path given\n\n```ruby\nyumrepo_server 'relative/yum/repo/path' do\n action :update\n options \"-v --quiet\" # An optional string of options to pass to the createrepo command\nend\n```\n\n##### :delete action\n\nDeletes the repository at the given path (basically delete the directory)\n\n```ruby\nyumrepo_server 'relative/yum/repo/path' do\n action :delete\nend\n```\n\nLicense and Authors\n-------------------\n\nAuthors: Michael Morris \nLicense: 3-clause BSD\n","maintainer":"Michael Morris","maintainer_email":"michael.m.morris@gmail.com","license":"3-clause BSD","platforms":{"redhat":">= 0.0.0","centos":">= 0.0.0","fedora":">= 0.0.0"},"dependencies":{"apache2":">= 0.0.0","logrotate":">= 0.0.0"},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{},"version":"0.1.0"} yumrepo_server/Gemfile.lock 0000664 0001750 0001750 00000012475 12317557576 015637 0 ustar morrm1 morrm1 GEM
remote: https://rubygems.org/
specs:
activesupport (3.2.17)
i18n (~> 0.6, >= 0.6.4)
multi_json (~> 1.0)
addressable (2.3.6)
akami (1.2.1)
gyoku (>= 0.4.0)
nokogiri
app_conf (0.4.2)
ast (1.1.0)
berkshelf (2.0.14)
activesupport (~> 3.2.0)
addressable (~> 2.3.4)
buff-shell_out (~> 0.1)
chozo (>= 0.6.1)
faraday (~> 0.8.0)
faraday (~> 0.8.5)
hashie (>= 2.0.2)
minitar (~> 0.5.4)
rbzip2 (~> 0.2.0)
retryable (~> 1.3.3)
ridley (~> 1.5.0)
solve (>= 0.5.0)
thor (~> 0.18.0)
buff-config (0.4.0)
buff-extensions (~> 0.3)
varia_model (~> 0.1)
buff-extensions (0.5.0)
buff-ignore (1.1.1)
buff-platform (0.1.0)
buff-ruby_engine (0.1.0)
buff-shell_out (0.1.1)
buff-ruby_engine (~> 0.1.0)
builder (3.2.2)
celluloid (0.14.1)
timers (>= 1.0.0)
celluloid-io (0.14.1)
celluloid (>= 0.14.1)
nio4r (>= 0.4.5)
chef (11.10.4)
chef-zero (~> 1.7, >= 1.7.2)
diff-lcs (~> 1.2, >= 1.2.4)
erubis (~> 2.7)
highline (~> 1.6, >= 1.6.9)
json (>= 1.4.4, <= 1.8.1)
mime-types (~> 1.16)
mixlib-authentication (~> 1.3)
mixlib-cli (~> 1.4)
mixlib-config (~> 2.0)
mixlib-log (~> 1.3)
mixlib-shellout (~> 1.3)
net-ssh (~> 2.6)
net-ssh-multi (~> 1.1)
ohai (~> 6.0)
pry (~> 0.9)
puma (~> 1.6)
rest-client (>= 1.0.4, < 1.7.0)
yajl-ruby (~> 1.1)
chef-zero (1.7.3)
hashie (~> 2.0)
json
mixlib-log (~> 1.3)
moneta (< 0.7.0)
rack
chefspec (3.4.0)
chef (~> 11.0)
fauxhai (~> 2.0)
rspec (~> 2.14)
chozo (0.6.1)
activesupport (>= 3.2.0)
hashie (>= 2.0.2)
multi_json (>= 1.3.0)
coderay (1.1.0)
diff-lcs (1.2.5)
diffy (3.0.3)
erubis (2.7.0)
faraday (0.8.9)
multipart-post (~> 1.2.0)
fauxhai (2.1.0)
net-ssh
ohai
ffi (1.9.3)
foodcritic (0.2.0)
git (1.2.6)
gssapi (1.0.3)
ffi (>= 1.0.1)
gyoku (1.1.1)
builder (>= 2.1.2)
hashie (2.0.5)
highline (1.6.21)
hitimes (1.2.1)
httpclient (2.3.4.1)
httpi (0.9.7)
rack
i18n (0.6.9)
ipaddress (0.8.0)
json (1.8.1)
knife-spork (1.3.2)
app_conf (>= 0.4.0)
chef (>= 11.0.0)
diffy (>= 3.0.1)
git (>= 1.2.5)
little-plugger (1.1.3)
logging (1.8.2)
little-plugger (>= 1.1.3)
multi_json (>= 1.8.4)
method_source (0.8.2)
mime-types (1.25.1)
mini_portile (0.5.3)
minitar (0.5.4)
mixlib-authentication (1.3.0)
mixlib-log
mixlib-cli (1.4.0)
mixlib-config (2.1.0)
mixlib-log (1.6.0)
mixlib-shellout (1.3.0)
moneta (0.6.0)
multi_json (1.9.2)
multipart-post (1.2.0)
net-http-persistent (2.9.4)
net-ssh (2.8.0)
net-ssh-gateway (1.2.0)
net-ssh (>= 2.6.5)
net-ssh-multi (1.2.0)
net-ssh (>= 2.6.5)
net-ssh-gateway (>= 1.2.0)
nio4r (1.0.0)
nokogiri (1.6.1)
mini_portile (~> 0.5.0)
nori (1.1.5)
ohai (6.20.0)
ipaddress
mixlib-cli
mixlib-config
mixlib-log
mixlib-shellout
systemu (~> 2.5.2)
yajl-ruby
parser (2.1.7)
ast (~> 1.1)
slop (~> 3.4, >= 3.4.5)
powerpack (0.0.9)
pry (0.9.12.6)
coderay (~> 1.0)
method_source (~> 0.8)
slop (~> 3.4)
puma (1.6.3)
rack (~> 1.2)
rack (1.5.2)
rainbow (2.0.0)
rake (10.2.2)
rbzip2 (0.2.0)
rest-client (1.6.7)
mime-types (>= 1.16)
retryable (1.3.5)
ridley (1.5.3)
addressable
buff-config (~> 0.2)
buff-extensions (~> 0.3)
buff-ignore (~> 1.1)
buff-shell_out (~> 0.1)
celluloid (~> 0.14.0)
celluloid-io (~> 0.14.0)
erubis
faraday (>= 0.8.4)
hashie (>= 2.0.2)
json (>= 1.7.7)
mixlib-authentication (>= 1.3.0)
net-http-persistent (>= 2.8)
net-ssh
nio4r (>= 0.5.0)
retryable
solve (>= 0.4.4)
varia_model (~> 0.1)
winrm (~> 1.1.0)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
rspec-core (2.14.8)
rspec-expectations (2.14.5)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.6)
rubocop (0.20.0)
json (>= 1.7.7, < 2)
parser (~> 2.1.7)
powerpack (~> 0.0.6)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.4)
ruby-progressbar (1.4.2)
rubyntlm (0.1.1)
savon (0.9.5)
akami (~> 1.0)
builder (>= 2.1.2)
gyoku (>= 0.4.0)
httpi (~> 0.9)
nokogiri (>= 1.4.0)
nori (~> 1.0)
wasabi (~> 1.0)
slop (3.5.0)
solve (0.8.2)
strainer (3.3.0)
berkshelf (~> 2.0)
buff-platform (~> 0.1)
systemu (2.5.2)
thor (0.18.1)
timers (2.0.0)
hitimes
uuidtools (2.1.4)
varia_model (0.3.2)
buff-extensions (~> 0.2)
hashie (>= 2.0.2)
wasabi (1.0.0)
nokogiri (>= 1.4.0)
winrm (1.1.3)
gssapi (~> 1.0.0)
httpclient (~> 2.2, >= 2.2.0.2)
logging (~> 1.6, >= 1.6.1)
nokogiri (~> 1.5)
rubyntlm (~> 0.1.1)
savon (= 0.9.5)
uuidtools (~> 2.1.2)
yajl-ruby (1.2.0)
PLATFORMS
ruby
DEPENDENCIES
chef (~> 11.0)
chefspec (~> 3.3)
foodcritic
knife-spork
rake
rubocop
strainer
yumrepo_server/LICENSE 0000664 0001750 0001750 00000002710 12317433507 014374 0 ustar morrm1 morrm1 Copyright (c) 2014, Mike Morris
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Mike Morris nor the names of any
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
yumrepo_server/Strainerfile 0000664 0001750 0001750 00000000370 12317433524 015740 0 ustar morrm1 morrm1 knife: bundle exec knife cookbook test $COOKBOOK
foodcritic: bundle exec foodcritic $SANDBOX/$COOKBOOK
rubocop: bundle exec rubocop $SANDBOX/$COOKBOOK
rspec: (cd $SANDBOX/$COOKBOOK && bundle exec rspec --color --format documentation)
yumrepo_server/CHANGELOG.md 0000664 0001750 0001750 00000000204 12317536050 015171 0 ustar morrm1 morrm1 yumrepo_server CHANGELOG
=========================
0.1.0
-----
- [michael.m.morris@gmail.com] - Initial release of yumrepo_server
yumrepo_server/attributes/ 0000775 0001750 0001750 00000000000 12317536120 015550 5 ustar morrm1 morrm1 yumrepo_server/attributes/default.rb 0000664 0001750 0001750 00000000156 12317342216 017524 0 ustar morrm1 morrm1 default['yum']['server']['repo_base_dir'] = '/var/lib/yum-repo'
default['apache']['include_logrotate'] = true
yumrepo_server/.rubocop.yml 0000664 0001750 0001750 00000000157 12317356365 015652 0 ustar morrm1 morrm1 Encoding:
Enabled: false
LineLength:
Max: 128
NumericLiterals:
Enabled: false
MethodLength:
Max: 40
yumrepo_server/recipes/ 0000775 0001750 0001750 00000000000 12317555125 015022 5 ustar morrm1 morrm1 yumrepo_server/recipes/default.rb 0000664 0001750 0001750 00000001304 12317555125 016771 0 ustar morrm1 morrm1 #
# Cookbook Name:: yumrepo_server
# Recipe:: default
#
# Copyright 2014, Pearson
#
# All rights reserved - Do Not Redistribute
#
package 'createrepo'
directory node['yum']['server']['repo_base_dir'] do
action :create
recursive true
end
# Going to use Apache web server, vs a lighter-weight HTTP
# server, since it's the only option available without
# needing to install the EPEL yum repo
include_recipe 'apache2'
include_recipe 'apache2::logrotate' if node['apache']['include_logrotate']
web_app 'yum-server' do
server_name node['hostname']
server_aliases node['fqdn']
docroot node['yum']['server']['repo_base_dir']
directory_options 'Indexes MultiViews FollowSymlinks'
rewrite 'Off'
end
yumrepo_server/README.md 0000664 0001750 0001750 00000006236 12317546401 014653 0 ustar morrm1 morrm1 yumrepo_server Cookbook
========================
This cookbook configures a Yum repository to be served from your system. It will automatically install and configure the Apache web server (as it's the only server that's available without requiring the EPEL yum repo). It also install the createrepo package for the utilities needed to setup a directory as a yum source.
Requirements
------------
#### cookbooks
- `apache2`
- `logrotate`
#### packages
- `httpd` - needed to serve the packages in the repository
- `createrepo` - needed to setup the repository
- `logrotate` - needed by the httpd package to configure log file management
#### platforms
Any system that uses Yum and has the required pakcages
Attributes
----------
#### yumrepo_server::default
* **['yum']['server']['repo\_base\_dir']**
_Type:_ String
_Description:_ The base directory where the repositories will be configured. Will be used as Apache's DocumentRoot
_Default:_ /var/lib/yum-repo
* **['apache']['include\_logrotate']**
_Type:_ Boolean
_Description:_ Flag to determine if logrotate will be configured for Apache logs
_Default:_ true
Usage
-----
### Recipes
#### yumrepo_server::default
Just include `yumrepo_server` in your node's `run_list`:
```json
{
"name":"my_node",
"run_list": [
"recipe[yumrepo_server]"
]
}
```
### LWRPs
#### yumrepo_server
##### :create action
Create a yum repository inside of the relative path given (will be rooted at node['yum']['server']['repo_base_dir'])
_With implied directory_
```ruby
yumrepo_server 'relative/yum/repo/path' do
action :create
options "-v --quiet" # An optional string of options to pass to the createrepo command
remote_source "http://upstream.com/path" # An optional URL string used as a base to retrieve packages from
packages %w(pkg1.rpm pkg2.rpm pkg3.rpm) # An optional array of package names to be configured in the repo (default is all packages). Required with the :remote_source attribute to specify which packages to retrieve.
end
```
_With explicit directory_
```ruby
yumrepo_server 'creates my yum repo' do
action :create
dir 'relative/yum/repo/path' # Required relative path to create repo at (this value will be appended to the value of node['yum']['server']['repo_base_dir'])
options "-v --quiet" # An optional string of options to pass to the createrepo command
remote_source "http://upstream.com/path" # An optional URL string used as a base to retrieve packages from
packages %w(pkg1.rpm pkg2.rpm pkg3.rpm) # An optional array of package names to be configured in the repo (default is all packages). Required with the :remote_source attribute to specify which packages to retrieve.
end
```
##### :update action
Update the the yum repository at the path given
```ruby
yumrepo_server 'relative/yum/repo/path' do
action :update
options "-v --quiet" # An optional string of options to pass to the createrepo command
end
```
##### :delete action
Deletes the repository at the given path (basically delete the directory)
```ruby
yumrepo_server 'relative/yum/repo/path' do
action :delete
end
```
License and Authors
-------------------
Authors: Michael Morris
License: 3-clause BSD
yumrepo_server/spec/ 0000775 0001750 0001750 00000000000 12317536166 014326 5 ustar morrm1 morrm1 yumrepo_server/spec/default_spec.rb 0000664 0001750 0001750 00000004057 12317536164 017315 0 ustar morrm1 morrm1 require 'spec_helper'
platforms = {
redhat: %w(6.3 6.4 6.5),
centos: %w(6.3 6.4 6.5),
fedora: %w(18 19 20)
}
platforms.each_pair do |p, v|
Array(v).each do |ver|
describe 'yumrepo_server::default' do
# Use an explicit subject
let(:chef_run) do
ChefSpec::Runner.new(platform: p.to_s, version: ver, log_level: :warn) do |node|
Chef::Log.debug(format('#### FILE: %s PLATFORM: %s VERSION: %s ####', ::File.basename(__FILE__), p, ver))
end.converge(described_recipe)
end
it 'creates the root repository directory' do
expect(chef_run).to create_directory '/var/lib/yum-repo'
end
it 'installs the createrepo package' do
expect(chef_run).to install_package 'createrepo'
end
it 'installs apache' do
expect(chef_run).to include_recipe 'apache2'
expect(chef_run).to install_package 'httpd'
end
it 'installs and configures logrotate' do
expect(chef_run).to include_recipe 'apache2::logrotate'
expect(chef_run).to include_recipe 'logrotate'
expect(chef_run).to install_package 'logrotate'
file = '/etc/logrotate.d/httpd'
expect(chef_run).to create_template file
expect(chef_run).to render_file file
end
it 'configures the yum repo in apache' do
file = '/etc/httpd/sites-available/yum-server.conf'
expect(chef_run).to create_template file
expect(chef_run).to render_file(file).with_content %r{DocumentRoot\s+/var/lib/yum-repo$}
expect(chef_run).to render_file(file).with_content %r{$}
expect(chef_run).to render_file(file).with_content %r{ErrorLog\s+/var/log/httpd/yum-server-error.log$}
expect(chef_run).to render_file(file).with_content %r{CustomLog\s+/var/log/httpd/yum-server-access.log combined$}
expect(chef_run).to render_file(file).with_content(/RewriteEngine\s+Off$/)
expect(chef_run).to render_file(file).with_content %r{RewriteLog\s+/var/log/httpd/yum-server-rewrite.log$}
end
end
end
end
yumrepo_server/spec/spec_helper.rb 0000664 0001750 0001750 00000000137 12317354536 017144 0 ustar morrm1 morrm1 # Added by ChefSpec
require 'chefspec'
require 'chefspec/berkshelf'
ChefSpec::Coverage.start!
yumrepo_server/templates/ 0000775 0001750 0001750 00000000000 12317337206 015364 5 ustar morrm1 morrm1 yumrepo_server/templates/default/ 0000775 0001750 0001750 00000000000 12317555713 017015 5 ustar morrm1 morrm1 yumrepo_server/templates/default/web_app.conf.erb 0000664 0001750 0001750 00000002740 12317351046 022044 0 ustar morrm1 morrm1
ServerName <%= @params[:server_name] %>
ServerAlias <% [@params[:server_aliases]].each do |a| %><%= a %> <% end %>
DocumentRoot <%= @params[:docroot] %>
>
Options <%= [@params[:directory_options] || "FollowSymLinks" ].flatten.join " " %>
AllowOverride <%= [@params[:allow_override] || "None" ].flatten.join " " %>
Order allow,deny
Allow from all
Options FollowSymLinks
AllowOverride None
SetHandler server-status
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
LogLevel info
ErrorLog <%= node['apache']['log_dir'] %>/<%= @params[:name] %>-error.log
CustomLog <%= node['apache']['log_dir'] %>/<%= @params[:name] %>-access.log combined
<% if @params[:directory_index] -%>
DirectoryIndex <%= [@params[:directory_index]].flatten.join " " %>
<% end -%>
RewriteEngine <%= @params[:rewrite] %>
RewriteLog <%= node['apache']['log_dir'] %>/<%= @application_name %>-rewrite.log
RewriteLogLevel 0
# Canonical host, <%= @params[:server_name] %>
RewriteCond %{HTTP_HOST} !^<%= @params[:server_name] %> [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*)$ http://<%= @params[:server_name] %>/$1 [L,R=301]
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /system/maintenance.html [L]