Merge "Use archive to fetch/checksum instead of wget."
This commit is contained in:
commit
3f33a3169e
22
lib/puppet/parser/functions/es_checksum.rb
Normal file
22
lib/puppet/parser/functions/es_checksum.rb
Normal file
@ -0,0 +1,22 @@
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:es_checksum, :type => :rvalue, :doc => <<-EOS
|
||||
This function returns the checksum from elastic search checksum file.
|
||||
*Examples:*
|
||||
es_checksum('https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.20.5.deb.sha1.txt')
|
||||
Would return: "b51e4dc55490bc03e54d7f8f2d41affc54773206"
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
raise(Puppet::ParseError, "es_checksum(): Wrong number of arguments " +
|
||||
"given (#{arguments.size} for 1)") if arguments.size != 1
|
||||
|
||||
begin
|
||||
require 'open-uri'
|
||||
result = open(arguments[0]).read
|
||||
result.split.first
|
||||
rescue Exception => e
|
||||
Puppet.debug("Unable to obtain elastic search checksum: #{e.message}")
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
@ -16,76 +16,60 @@
|
||||
#
|
||||
class elasticsearch (
|
||||
$version = '0.20.5',
|
||||
$checksum = undef,
|
||||
$url = 'https://download.elasticsearch.org/elasticsearch/elasticsearch',
|
||||
$heap_size = '16g',
|
||||
$es_template_config = {}
|
||||
$es_template_config = {},
|
||||
) {
|
||||
# install java runtime
|
||||
if ! defined(Package['openjdk-7-jre-headless']) {
|
||||
package { 'openjdk-7-jre-headless':
|
||||
ensure => present,
|
||||
}
|
||||
}
|
||||
|
||||
# Ensure: java runtime and curl
|
||||
# Curl is handy for talking to the ES API on localhost. Allows for
|
||||
# querying cluster state and deleting indexes and so on.
|
||||
if ! defined(Package['curl']) {
|
||||
package { 'curl':
|
||||
ensure => present,
|
||||
}
|
||||
ensure_packages(['openjdk-7-jre-headless', 'curl'])
|
||||
|
||||
include '::archive'
|
||||
|
||||
$package_name = "elasticsearch-${version}.deb"
|
||||
$source_url = "${url}/${package_name}"
|
||||
$source_checksum = "${source_url}.sha1.txt"
|
||||
|
||||
if $checksum {
|
||||
$es_checksum = $checksum
|
||||
} else {
|
||||
$es_checksum = es_checksum($source_checksum)
|
||||
}
|
||||
|
||||
exec { 'get_elasticsearch_deb':
|
||||
command => "wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-${version}.deb -O /tmp/elasticsearch-${version}.deb",
|
||||
path => '/bin:/usr/bin',
|
||||
creates => "/tmp/elasticsearch-${version}.deb",
|
||||
if $es_checksum {
|
||||
$checksum_type = 'sha1'
|
||||
} else {
|
||||
$checksum_type = 'none'
|
||||
}
|
||||
|
||||
exec { 'gen_elasticsearch_deb_sha1':
|
||||
command => "sha1sum elasticsearch-${version}.deb > /tmp/elasticsearch-${version}.deb.sha1.gen",
|
||||
path => '/bin:/usr/bin',
|
||||
cwd => '/tmp',
|
||||
creates => "/tmp/elasticsearch-${version}.deb.sha1.gen",
|
||||
require => [
|
||||
Exec['get_elasticsearch_deb'],
|
||||
]
|
||||
}
|
||||
|
||||
exec { 'get_elasticsearch_deb_sha1':
|
||||
command => "wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-${version}.deb.sha1.txt -O /tmp/elasticsearch-${version}.deb.sha1.txt",
|
||||
path => '/bin:/usr/bin',
|
||||
creates => "/tmp/elasticsearch-${version}.deb.sha1.txt",
|
||||
}
|
||||
|
||||
exec { 'check_elasticsearch_sha1':
|
||||
command => "diff /tmp/elasticsearch-${version}.deb.sha1.txt /tmp/elasticsearch-${version}.deb.sha1.gen",
|
||||
path => '/bin:/usr/bin',
|
||||
subscribe => Exec['get_elasticsearch_deb'],
|
||||
refreshonly => true,
|
||||
require => [
|
||||
Exec['gen_elasticsearch_deb_sha1'],
|
||||
Exec['get_elasticsearch_deb_sha1'],
|
||||
]
|
||||
archive { "/tmp/elasticsearch-${version}.deb":
|
||||
source => $source_url,
|
||||
extract => false,
|
||||
checksum => $es_checksum,
|
||||
checksum_type => $checksum_type,
|
||||
}
|
||||
|
||||
# install elastic search
|
||||
package { 'elasticsearch':
|
||||
ensure => latest,
|
||||
source => "/tmp/elasticsearch-${version}.deb",
|
||||
provider => 'dpkg',
|
||||
subscribe => Exec['get_elasticsearch_deb_sha1'],
|
||||
require => [
|
||||
ensure => latest,
|
||||
source => "/tmp/elasticsearch-${version}.deb",
|
||||
provider => 'dpkg',
|
||||
require => [
|
||||
Package['openjdk-7-jre-headless'],
|
||||
File['/etc/elasticsearch/elasticsearch.yml'],
|
||||
File['/etc/elasticsearch/default-mapping.json'],
|
||||
File['/etc/default/elasticsearch'],
|
||||
Archive["/tmp/elasticsearch-${version}.deb"],
|
||||
]
|
||||
}
|
||||
|
||||
file { '/etc/elasticsearch':
|
||||
ensure => directory,
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0755',
|
||||
ensure => directory,
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0755',
|
||||
}
|
||||
|
||||
file { '/etc/elasticsearch/elasticsearch.yml':
|
||||
@ -95,15 +79,13 @@ class elasticsearch (
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0644',
|
||||
require => File['/etc/elasticsearch'],
|
||||
}
|
||||
|
||||
file { '/etc/elasticsearch/templates':
|
||||
ensure => directory,
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0755',
|
||||
require => File['/etc/elasticsearch'],
|
||||
ensure => directory,
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0755',
|
||||
}
|
||||
|
||||
file { '/etc/elasticsearch/default-mapping.json':
|
||||
@ -113,7 +95,6 @@ class elasticsearch (
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0644',
|
||||
require => File['/etc/elasticsearch'],
|
||||
}
|
||||
|
||||
file { '/etc/default/elasticsearch':
|
||||
|
1
tests/init.pp
Normal file
1
tests/init.pp
Normal file
@ -0,0 +1 @@
|
||||
include '::elasticsearch'
|
Loading…
x
Reference in New Issue
Block a user