Skip to content

Commit

Permalink
Add APT packages
Browse files Browse the repository at this point in the history
- Adding apt/* and debian manifests to deal with APT sources.
  So far hardcoding Sensuapp ones as from Sensu wiki

- Add init.pp to be compliant with Puppet module guidelines
  • Loading branch information
Alexander Fortin committed Jul 5, 2012
1 parent 13f8230 commit dda9188
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
45 changes: 45 additions & 0 deletions manifests/apt/key.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#
# Add/remove an apt key
#
# == Parameters:
#
# $title:: The key id
# $ensure:: "present" or "absent"
# $url:: The url of the key
# $server:: The server from which download the key
# url or server are required on ensure is "present"
#
define sensu::apt::key($ensure, $url = '', $server = '') {

case $ensure {

'present': {

if $url != '' {
exec { "apt-key_present_$title":
command => "/usr/bin/wget -O- -q '${url}' | /usr/bin/apt-key add -",
unless => "/usr/bin/apt-key list | /bin/grep -c '$title'",
}
} else {
exec { "apt-key_present_$title":
command => "/usr/bin/apt-key adv --keyserver '${server}' --recv '${title}'",
unless => "/usr/bin/apt-key list | /bin/grep -c '$title'",
}
}

}

'absent': {

exec { "apt-key_absent_$title":
command => "/usr/bin/apt-key del '$title'",
onlyif => "/usr/bin/apt-key list | /bin/grep -c '$title'",
}

}

default: {
fail "Invalid 'ensure' value '$ensure' for apt::key"
}
}
}
43 changes: 43 additions & 0 deletions manifests/apt/source.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

#
# Add/remove a source
#
# == Parameters:
#
# $title:: The source name
# $ensure:: "present" or "absent"
# $content:: The content to add to source.list
#
define sensu::apt::source($ensure, $content = '') {

$filepath = "/etc/apt/sources.list.d/${title}.list"

case $ensure {

'present': {

file { "add_apt_source_$filepath":
path => $filepath,
content => $content
}

exec { "update_apt_source_$filepath":
command => '/usr/bin/apt-get update',
subscribe => File["add_apt_source_$filepath"],
refreshonly => true
}

}

'absent': {

file { $filepath:
ensure => absent
}
}

default: {
fail "Invalid 'ensure' value '$ensure' for apt::source"
}
}
}
15 changes: 15 additions & 0 deletions manifests/debian.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

class sensu::debian {

sensu::apt::key { 'sensuapp':
ensure => 'present',
url => 'http://repos.sensuapp.org/apt/pubkey.gpg',
}

sensu::apt::source { 'sensuapp':
ensure => 'present',
content => 'deb http://repos.sensuapp.org/apt sensu main',
require => Sensu::Apt::Key['sensuapp'],
}

}
11 changes: 11 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

class sensu {

case $::operatingsystem {
# add apt sources
'Debian': { include 'sensu::debian' }
'Ubuntu': { include 'sensu::debian' }
default : {}
}

}

0 comments on commit dda9188

Please sign in to comment.