diff --git a/manifests/apt/key.pp b/manifests/apt/key.pp new file mode 100644 index 0000000000..872740deef --- /dev/null +++ b/manifests/apt/key.pp @@ -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" + } + } +} diff --git a/manifests/apt/source.pp b/manifests/apt/source.pp new file mode 100644 index 0000000000..590a7a4d48 --- /dev/null +++ b/manifests/apt/source.pp @@ -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" + } + } +} diff --git a/manifests/debian.pp b/manifests/debian.pp new file mode 100644 index 0000000000..786a3a000d --- /dev/null +++ b/manifests/debian.pp @@ -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'], + } + +} diff --git a/manifests/init.pp b/manifests/init.pp new file mode 100644 index 0000000000..ef8faa8df3 --- /dev/null +++ b/manifests/init.pp @@ -0,0 +1,11 @@ + +class sensu { + + case $::operatingsystem { + # add apt sources + 'Debian': { include 'sensu::debian' } + 'Ubuntu': { include 'sensu::debian' } + default : {} + } + +}