Permalink
Browse files

Enable hiera_hash merge to get parameters for apt

This is just a fork of the official puppetlabs [pt module
with a tweak to enable hash merge from hiera instead of the default priority
lookup to get the sources, settings, keys and ppas.
  • Loading branch information...
Guillaume
Guillaume committed Aug 28, 2015
1 parent 418820a commit 7aeb9667be3c34a9c78db5f690b4ef36ef39293c
Showing with 97 additions and 24 deletions.
  1. +30 −6 README.md
  2. +60 −12 manifests/init.pp
  3. +7 −6 metadata.json
@@ -3,23 +3,47 @@
#### Table of Contents

1. [Overview](#overview)
2. [Module Description - What the module does and why it is useful](#module-description)
3. [Setup - The basics of getting started with apt](#setup)
2. [Why this fork](#why-this-fork)
3. [Module Description - What the module does and why it is useful](#module-description)
4. [Setup - The basics of getting started with apt](#setup)
* [What apt affects](#what-apt-affects)
* [Beginning with apt](#beginning-with-apt)
4. [Usage - Configuration options and additional functionality](#usage)
5. [Reference - An under-the-hood peek at what the module is doing and how](#reference)
5. [Usage - Configuration options and additional functionality](#usage)
6. [Reference - An under-the-hood peek at what the module is doing and how](#reference)
* [Classes](#classes)
* [Defines](#defines)
* [Types](#types)
* [Facts](#facts)
6. [Limitations - OS compatibility, etc.](#limitations)
7. [Development - Guide for contributing to the module](#development)
7. [Limitations - OS compatibility, etc.](#limitations)
8. [Development - Guide for contributing to the module](#development)

## Overview

The apt module lets you use Puppet to manage Apt sources, keys, and other configuration options.

## Why this fork

This is just a fork of the official puppetlabs [apt module](https://forge.puppetlabs.com/puppetlabs/apt)
with a tweak to enable hash merge from hiera instead of the default priority
lookup to get the sources, settings, keys and ppas.

This module is a drop-in replacement, fully compatible with the puppetlabs
version. The only beahoviour difference you will notice is that if you use
hiera, your values will be merged along the hierarchy instead of having only the
most specific used.

<rant>

According to Colleen Murphy@puppet-labs, not using hiera in puppet-labs
modules is by design ([MODULES-1507](https://tickets.puppetlabs.com/browse/MODULES-1507)).
In this case we should apparently either copy/edit a sources.list file ad
nauseam, or create a huge collection of files for the sources.list.d dir
and pick and choose per host/role, but the choice will always be on one
hierarchy level.
We want something more practical: a merge of the different levels.

</rant>

## Module Description

Apt (Advanced Package Tool) is a package manager available on Debian, Ubuntu, and several other operating systems. The apt module provides a series of classes, defines, types, and facts to help you automate Apt package management.
@@ -9,6 +9,54 @@
$settings = {},
) inherits ::apt::params {

# See rant regarding lookups and merging in Readme
if (empty($sources) or !$sources) {
# no hiera, no direct param
$all_sources=undef
} elsif (! empty (hiera_hash('apt::sources', {}))) {
# sources comes from hiera => override
$all_sources = hiera_hash('apt::sources')
} else {
# sources comes as direct parameter: leave alone
$all_sources=$sources
}

# See rant regarding lookups and merging in Readme
if (empty($settings) or ! $settings) {
# no hiera, no direct param
$all_settings=undef
} elsif (! empty (hiera_hash('apt::settings', {}))) {
# settings comes from hiera => override
$all_settings = hiera_hash('apt::settings')
} else {
# settings comes as direct parameter: leave alone
$all_settings=$settings
}

# See rant regarding lookups and merging in Readme
if (empty($keys) or ! $keys) {
# no hiera, no direct param
$all_keys={}
} elsif (! empty (hiera_hash('apt::keys', {}))) {
# keys comes from hiera => override
$all_keys = hiera_hash('apt::keys')
} else {
# keys comes as direct parameter: leave alone
$all_keys=$keys
}

# See rant regarding lookups and merging in Readme
if (empty($ppas) or ! $ppas) {
# no hiera, no direct param
$all_ppas={}
} elsif (! empty (hiera_hash('apt::ppas', {}))) {
# ppas comes from hiera => override
$all_ppas = hiera_hash('apt::ppas')
} else {
# ppas comes as direct parameter: leave alone
$all_ppas=$ppas
}

$frequency_options = ['always','daily','weekly','reluctantly']
validate_hash($update)
if $update['frequency'] {
@@ -62,10 +110,10 @@

$_proxy = merge($apt::proxy_defaults, $proxy)

validate_hash($sources)
validate_hash($keys)
validate_hash($settings)
validate_hash($ppas)
validate_hash($all_sources)
validate_hash($all_keys)
validate_hash($all_settings)
validate_hash($all_ppas)

if $_proxy['ensure'] == 'absent' or $_proxy['host'] {
apt::setting { 'conf-proxy':
@@ -138,19 +186,19 @@
}

# manage sources if present
if $sources {
create_resources('apt::source', $sources)
if $all_sources {
create_resources('apt::source', $all_sources)
}
# manage keys if present
if $keys {
create_resources('apt::key', $keys)
if $all_keys {
create_resources('apt::key', $all_keys)
}
# manage ppas if present
if $ppas {
create_resources('apt::ppa', $ppas)
if $all_ppas {
create_resources('apt::ppa', $all_ppas)
}
# manage settings if present
if $settings {
create_resources('apt::setting', $settings)
if $all_settings {
create_resources('apt::setting', $all_settings)
}
}
@@ -1,12 +1,12 @@
{
"name": "puppetlabs-apt",
"name": "lomignet-apt",
"version": "2.1.1",
"author": "Puppet Labs",
"author": "Coen, Guillaume <https://github.com/lomignet>",
"summary": "Provides an interface for managing Apt source, key, and definitions with Puppet",
"license": "Apache-2.0",
"source": "https://github.com/puppetlabs/puppetlabs-apt",
"project_page": "https://github.com/puppetlabs/puppetlabs-apt",
"issues_url": "https://tickets.puppetlabs.com/browse/MODULES",
"source": "https://github.com/lomignet/lomignet-apt",
"project_page": "https://github.com/lomignet/lomignet-apt",
"issues_url": "https://github.com/lomignet/lomignet-apt/issues",
"dependencies": [
{"name":"puppetlabs/stdlib","version_requirement":">= 4.5.0 < 5.0.0"}
],
@@ -15,7 +15,8 @@
"operatingsystem": "Debian",
"operatingsystemrelease": [
"6",
"7"
"7",
"8"
]
},
{

1 comment on commit 7aeb966

@cdemeijer

This comment has been minimized.

Copy link

cdemeijer commented on 7aeb966 Aug 28, 2015

Good to see the changes published. Maybe remove the rant tags?

Please sign in to comment.