Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
ea0b7c8
Make package's "ensure" explicit and configurable.
lelutin Oct 16, 2010
1ba3928
Add a little flexibility in config file sources.
lelutin Oct 16, 2010
7b89dd3
Add Makefile; smoke test.
garthk Apr 4, 2012
e9a9b62
Add Vagrantfile; edit Makefile for 'make vm'.
garthk Apr 4, 2012
9813d84
Add README file.
garthk Apr 4, 2012
765a8b7
Make the VM use itself as a cache.
garthk Apr 4, 2012
06fca62
Added README text on how to use Puppet to configure clients.
garthk Apr 4, 2012
fb017c9
Added `make smoke` for a quicker smoke test.
garthk Apr 4, 2012
ca572a0
Applied Puppet style guide.
garthk Apr 4, 2012
3588359
Added class for client machines.
garthk Apr 4, 2012
19f9bfc
More documentation work.
garthk Apr 4, 2012
8f1cd25
Merged changes by lelutin for file source variety and picking versions.
garthk Apr 4, 2012
5823b5c
Gave credit where due.
garthk Apr 4, 2012
3763add
Brought in Lekensteyn's detect-http-proxy script.
garthk Apr 5, 2012
6e1cd58
Added autodetect capability. ARGUMENTS CHANGED.
garthk Apr 5, 2012
14b5677
Deleted blank README.
garthk Apr 5, 2012
8770454
README: fixed credits; corrected self-caching detail.
garthk Apr 6, 2012
1efea22
README: added note on which releases support ProxyAutoDetect.
garthk Apr 6, 2012
a842be0
Merge remote-tracking branch 'garthk/master'
lelutin Apr 19, 2012
987174e
Use "modules" explicitly in the server config source.
lelutin Apr 19, 2012
aff868d
Fixed show_proxy_messages default. Thanks, Lekensteyn!
garthk Apr 24, 2012
f8e9771
Fixed README to match actual behaviour. Thanks, lelutin!
garthk Apr 24, 2012
da46266
Merge remote-tracking branch 'garthk/master'
lelutin Apr 24, 2012
9dce785
Correct style for init.pp
lelutin Apr 24, 2012
91a913b
Merge remote-tracking branch 'albanpeignier/master'
lelutin Sep 25, 2012
e8742a0
Set proxy detection timeout to 2 seconds
insertjokehere Feb 28, 2013
97595d4
converted detect-http-proxy to a template to allow for configurable t…
insertjokehere Apr 5, 2013
1a364aa
simplified setting of timeout values, updated README. This adds puppe…
insertjokehere May 13, 2013
3eb4d81
workaround for bug #683803 (errors in combination with http.debian.net)
lluis Oct 11, 2013
8432d5a
variables without @ are deprecated
lluis Oct 11, 2013
3f3a66b
add 2 seconds timeout to avoid long waits when proxy ip is not reachable
lluis Oct 15, 2013
7069a77
Merge pull request #2 from insertjokehere/master
lelutin Dec 11, 2013
99d0e98
Split things into logical blocks as per best practices
lelutin Mar 12, 2014
a8dab13
Rename module to apt_cacher_ng
lelutin Mar 12, 2014
44cd727
Update README to use new module name
lelutin Mar 12, 2014
986152c
Move argument checking to main client class
lelutin Mar 12, 2014
09701fb
Lint manifests
lelutin Mar 12, 2014
a45f526
Remove $server parameter and move remaining parameter-logic up to client
lelutin Mar 12, 2014
8825efe
Split modes and reuse resources
lelutin Mar 12, 2014
068944f
default value for $servers should include port
lelutin Mar 12, 2014
642edc2
Update README to document all changes correctly
lelutin Mar 12, 2014
1d92356
README: Better formatting
lelutin Mar 12, 2014
e1142d9
README: server code block is not syntax-highlighted
lelutin Mar 12, 2014
92c97c6
Correct mention to Garth Kidd.
lelutin Mar 12, 2014
c7befc8
Make it possible to set admin auth
lelutin Mar 27, 2014
2ddd0c8
Tests don't use the new name with underscores.
lelutin Mar 27, 2014
9d8228a
README: Document admin auth
lelutin Mar 27, 2014
3156316
Anchor names are too generic and clash between server and client
Mar 24, 2015
69f76df
Merge remote-tracking branch 'lluis/master'
lelutin Sep 29, 2015
aa589ee
Apply license GPLv3
lelutin Oct 8, 2016
98de133
better arrow alignment for ordering
lelutin Jun 26, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vagrant
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apply = puppet apply --noop --modulepath=tests/modules

smoke:
$(apply) tests/smoke.pp
$(apply) tests/client.pp
$(apply) tests/autodetect.pp

test: tests/*.pp
find tests -name \*.pp | xargs -n 1 -t $(apply)

vm:
vagrant up
Empty file removed README
Empty file.
169 changes: 169 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
# puppet-apt_cacher_ng

A Puppet module for [apt-cacher-ng], with a `Vagrantfile` for quick
deployment on [Vagrant].

Requires puppetlabs [stdlib] module

Original author: [Alban Peignier]

Other contributors:

* [Garth Kidd]: Vagrantfile and smoke tests
* [Gabriel Filion]: version specification, file layout flexibility
* [Lekensteyn]: auto-detect/fallback script (see [askubuntu:54099])

## Usage

The apt\_cacher\_ng module provides two main "entry points": one for the server
and one for clients.

### Server

The main class, `apt_cacher_ng` will install the apt_cacher_ng server. You can
simply include the class, or if you want to install a specific version you can
use the `version` parameter like the following:

```puppet
class { 'apt_cacher_ng':
version => '0.4.6-1ubuntu1',
}
```

* The server will be available on the default port (3142).
* The server will not use itself as a cache by default.

If you'd like to set an admin password for the web interface, you can do so
with the `admin_user` and `admin_pw` parameters. Make sure to set both
parameters (or none). Also, keep in mind that only alphanumeric characters,
dashes and underscores are accepted for the password:

```puppet
class { 'apt_cacher_ng':
admin_user => 'clown_goose',
admin_pw => '12tgDd23456ytGfDW32',
}
```

### Client

The class `apt_cacher_ng::client` helps you configure a server as a client
for an apt proxy. It has two "modes" of configuration: setting up one proxy
with no alternative, and setting up a list of proxies where the first in the
list that is currently available will be used (autodetection).

Both modes use the `servers` parameter to the `apt_cacher_ng::client` class.
This parameter should be an array that contains server strings. The servers
strings are fqdn (or IP address) and port in the same mannger as you'd write
it for HTTP, without the "http://" prefix.

* To setup one proxy with no fallback, set the `autodetect` parameter to
`false` and make sure to provide only one server value for the `servers`
parameter:

```puppet
class { 'apt_cacher_ng::client':
servers => ['192.168.31.42:3142'],
autodetect => false,
}
```

Per [askubuntu:54099], you'll need to do this on older Ubuntu and Debian
releases. Lucid and Squeeze support `Acquire::http::ProxyAutoDetect`;
Karmic and Lenny don't.

* To setup a list of proxies, keep the `autodetect` paramter to a value of
`true` (this is the default value) and specify all servers in the `servers`
parameter:

```puppet
class { 'apt_cacher_ng::client':
servers => ['192.168.30.42:3142', '192.168.31.42:3142'],
}
```

When setting up autodetect, you can override the number of seconds till
timeout (default is 30):

```puppet
class { 'apt_cacher_ng::client':
servers => ['192.168.30.42:3142', '192.168.31.42:3142'],
timeout => 15,
}
```

Also when setting up autodetect, you can set the `verbose` parameter to
`false` to make the autodetection process act quietly:

```puppet
class { 'apt_cacher_ng::client':
servers => ['192.168.30.42:3142', '192.168.31.42:3142'],
verbose => false,
}
```

## Providing an apt cache for your Vagrant virtual machines

To install apt-cacher-ng on a fresh box in [Vagrant]:

vagrant up aptcache

The `Vagrantfile` specifies a box named `aptcache` providing its service
from `http://192.168.31.42:3142`. You should be able to browse to it from
your host OS to manage it.

### Using the apt cache

To configure your own Vagrant box to access the `aptcache` box:

* Configure your VM for [host-only networking], by adding the following line
to your `Vagrantfile`:

config.vm.network :hostonly, "192.168.31.2"

(Change the final octet (`2`) to make sure it's unique on your machine.
Don't use `1`: it'll probably be used by your host OS for its `vboxnet0`
adapter.)

* Inside your box, create `/etc/apt/apt.conf.d/71proxy` with the line:

Acquire::http { Proxy "http://192.168.31.42:3142"; };

If you're using [Puppet Provisioning], put this in your `manifest_file`,
e.g. `my_manifest.pp`:

file { "/etc/apt/apt.conf.d/71proxy":
owner => root,
group => root,
mode => '0644',
content => 'Acquire::http { Proxy "http://192.168.31.42:3142"; };',
}

You could also install the Puppet module and use `apt_cacher_ng::client`
as above.

## Testing

To perform a [smoke test]:

make smoke

To smoke test both the module and the `Vagrantfile`'s `manifest_file`:

make test

To test the module properly, install [Vagrant] and:

make vm

[apt-cacher-ng]: http://www.unix-ag.uni-kl.de/~bloch/acng/
[smoke test]: http://docs.puppetlabs.com/guides/tests_smoke.htm
[stdlib]: https://github.com/puppetlabs/puppetlabs-stdlib
[Alban Peignier]: https://github.com/albanpeignier
[Garth Kidd]: https://github.com/garthk
[Gabriel Filion]: https://github.com/lelutin
[Lekensteyn]: http://www.lekensteyn.nl/
[Vagrant]: http://vagrantup.com/
[host-only networking]: http://vagrantup.com/docs/host_only_networking.html
[askubuntu:54099]: http://askubuntu.com/a/54099
[Puppet Provisioning]: http://vagrantup.com/docs/provisioners/puppet.html
19 changes: 19 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant::Config.run do |config|
config.vm.define :aptcache do |aptcache|
aptcache.vm.box = "lucid32"
aptcache.vm.host_name = "aptcache"
aptcache.vm.share_folder "module", "/tmp/vagrant-puppet/modules/apt_cacher_ng", ".", :create => true
aptcache.vm.network :hostonly, "192.168.31.42"
aptcache.vm.forward_port 3142, 3142
aptcache.vm.forward_port 22, 2242
aptcache.ssh.max_tries = 150
aptcache.vm.provision :puppet do |puppet|
puppet.manifests_path = "tests"
puppet.manifest_file = "vagrant.pp"
puppet.options = ["--modulepath", "/tmp/vagrant-puppet/modules"]
end
end
end
8 changes: 8 additions & 0 deletions files/30detectproxy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Fail immediately if a file could not be retrieved. Comment if you have a bad
# Internet connection
Acquire::Retries 0;

# undocumented feature which was found in the source. It should be an absolute
# path to the program, no arguments are allowed. stdout contains the proxy
# server, stderr is shown (in stderr) but ignored by APT
Acquire::http::ProxyAutoDetect "/etc/apt/detect-http-proxy";
3 changes: 3 additions & 0 deletions files/acng.conf
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,6 @@ ExTreshold: 4
#VfilePattern = (^|.*?/)(Index|Packages\.gz|Packages\.bz2|Release|Release\.gpg|Sources\.gz|Sources\.bz2|release|index\.db-.*\.gz|Contents-[^/]*\.gz|pkglist[^/]*\.bz2|rclist[^/]*\.bz2|Translation[^/]*\.bz2)$
#PfilePattern = .*(\.deb|\.rpm|\.dsc|\.tar\.gz\.gpg|\.tar\.gz|\.diff\.gz|\.diff\.bz2|\.jigdo|\.template|changelog|copyright|\.udeb|\.diff/.*\.gz|vmlinuz|initrd\.gz)$

# workaround to allow use of http.debian.net, see bug #683803
# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=683803
RedirMax: 0
25 changes: 25 additions & 0 deletions manifests/client.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class apt_cacher_ng::client (
$servers = $apt_cacher_ng::client::params::servers,
$autodetect = $apt_cacher_ng::client::params::autodetect,
$verbose = $apt_cacher_ng::client::params::verbose,
$timeout = $apt_cacher_ng::client::params::timeout
) inherits apt_cacher_ng::client::params {

validate_array($servers)
if empty($servers) {
fail('$servers must contain at least one value.')
}
if (! $autodetect) and (count($servers) > 1) {
fail('With $autodetect turned off, you can only specify one server.')
}
validate_bool($autodetect)
validate_bool($verbose)
if !is_integer($timeout) {
fail('Parameter $timeout is expected to be an integer value.')
}

anchor { 'apt_cacher_ng::client::begin': } ->
class { 'apt_cacher_ng::client::config': } ->
anchor { 'apt_cacher_ng::client::end': }

}
32 changes: 32 additions & 0 deletions manifests/client/autodetect.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class apt_cacher_ng::client::autodetect (
$ensure = present
) {

file { '/etc/apt/apt.conf.d/30detectproxy':
ensure => $ensure,
source => 'puppet:///modules/apt_cacher_ng/30detectproxy',
owner => 'root',
group => 0,
mode => '0644',
}

$show_proxy_messages = bool2num($apt_cacher_ng::client::verbose)

$proxies = $apt_cacher_ng::client::servers

file { '/etc/apt/detect-http-proxy':
ensure => $ensure,
content => template('apt_cacher_ng/detect-http-proxy.erb'),
owner => 'root',
group => 0,
mode => '0755',
}
file { '/etc/apt/proxy.conf':
ensure => $ensure,
content => template('apt_cacher_ng/apt-proxy-conf.erb'),
owner => 'root',
group => 0,
mode => '0644',
}

}
16 changes: 16 additions & 0 deletions manifests/client/config.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class apt_cacher_ng::client::config {

if ! $apt_cacher_ng::client::autodetect {
include apt_cacher_ng::client::one_proxy
class { 'apt_cacher_ng::client::autodetect':
ensure => absent,
}
}
else {
class { 'apt_cacher_ng::client::one_proxy':
ensure => absent,
}
include apt_cacher_ng::client::autodetect
}

}
14 changes: 14 additions & 0 deletions manifests/client/one_proxy.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class apt_cacher_ng::client::one_proxy (
$ensure = present
) {

$server = $apt_cacher_ng::client::servers[0]
file { '/etc/apt/apt.conf.d/71proxy':
ensure => $ensure,
content => "Acquire::http { Proxy \"http://${server}\"; };",
owner => 'root',
group => 0,
mode => '0644',
}

}
8 changes: 8 additions & 0 deletions manifests/client/params.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class apt_cacher_ng::client::params {

$servers = ['127.0.0.1:3142']
$autodetect = true
$verbose = true
$timeout = 30

}
26 changes: 26 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class apt_cacher_ng::config {

file { '/etc/apt-cacher-ng/acng.conf':
source => [
"puppet:///modules/site_apt_cacher_ng/${::fqdn}/acng.conf",
'puppet:///modules/site_apt_cacher_ng/acng.conf',
'puppet:///modules/apt_cacher_ng/acng.conf'
],
}

file { '/var/cache/apt-cacher-ng':
ensure => directory,
owner => 'apt-cacher-ng',
}

$admin_user = $apt_cacher_ng::admin_user
$admin_pw = $apt_cacher_ng::admin_pw
file { '/etc/apt-cacher-ng/security.conf':
ensure => present,
owner => 'root',
group => 'apt-cacher-ng',
mode => '0640',
content => template('apt_cacher_ng/security.conf.erb'),
}

}
34 changes: 18 additions & 16 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
class apt-cacher-ng {
class apt_cacher_ng (
$version = 'installed',
$admin_user = false,
$admin_pw = false
) {

package { apt-cacher-ng: }

service { apt-cacher-ng:
ensure => running,
require => Package[apt-cacher-ng]
if $admin_user != false and $admin_pw != false {
validate_string($admin_user)
validate_string($admin_pw)
}

file { "/etc/apt-cacher-ng/acng.conf":
source => "puppet:///apt-cacher-ng/acng.conf",
notify => Service[apt-cacher-ng],
require => Package[apt-cacher-ng]
else {
if ($admin_user != false and $admin_pw == false) or
($admin_user == false and $admin_pw != false) {
fail('Please set either none or both of $admin_user and $admin_pw.')
}
}

file { "/var/cache/apt-cacher-ng":
owner => apt-cacher-ng,
ensure => directory,
require => Package[apt-cacher-ng]
}
anchor { 'apt_cacher_ng::begin': }
-> class { 'apt_cacher_ng::install': }
-> class { 'apt_cacher_ng::config': }
~> class { 'apt_cacher_ng::service': }
-> anchor { 'apt_cacher_ng::end': }

}
7 changes: 7 additions & 0 deletions manifests/install.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class apt_cacher_ng::install {

package { 'apt-cacher-ng':
ensure => $apt_cacher_ng::version,
}

}
Loading