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,55 +16,39 @@
|
|||||||
#
|
#
|
||||||
class elasticsearch (
|
class elasticsearch (
|
||||||
$version = '0.20.5',
|
$version = '0.20.5',
|
||||||
|
$checksum = undef,
|
||||||
|
$url = 'https://download.elasticsearch.org/elasticsearch/elasticsearch',
|
||||||
$heap_size = '16g',
|
$heap_size = '16g',
|
||||||
$es_template_config = {}
|
$es_template_config = {},
|
||||||
) {
|
) {
|
||||||
# install java runtime
|
# Ensure: java runtime and curl
|
||||||
if ! defined(Package['openjdk-7-jre-headless']) {
|
|
||||||
package { 'openjdk-7-jre-headless':
|
|
||||||
ensure => present,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Curl is handy for talking to the ES API on localhost. Allows for
|
# Curl is handy for talking to the ES API on localhost. Allows for
|
||||||
# querying cluster state and deleting indexes and so on.
|
# querying cluster state and deleting indexes and so on.
|
||||||
if ! defined(Package['curl']) {
|
ensure_packages(['openjdk-7-jre-headless', 'curl'])
|
||||||
package { 'curl':
|
|
||||||
ensure => present,
|
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':
|
if $es_checksum {
|
||||||
command => "wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-${version}.deb -O /tmp/elasticsearch-${version}.deb",
|
$checksum_type = 'sha1'
|
||||||
path => '/bin:/usr/bin',
|
} else {
|
||||||
creates => "/tmp/elasticsearch-${version}.deb",
|
$checksum_type = 'none'
|
||||||
}
|
}
|
||||||
|
|
||||||
exec { 'gen_elasticsearch_deb_sha1':
|
archive { "/tmp/elasticsearch-${version}.deb":
|
||||||
command => "sha1sum elasticsearch-${version}.deb > /tmp/elasticsearch-${version}.deb.sha1.gen",
|
source => $source_url,
|
||||||
path => '/bin:/usr/bin',
|
extract => false,
|
||||||
cwd => '/tmp',
|
checksum => $es_checksum,
|
||||||
creates => "/tmp/elasticsearch-${version}.deb.sha1.gen",
|
checksum_type => $checksum_type,
|
||||||
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'],
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# install elastic search
|
# install elastic search
|
||||||
@ -72,12 +56,12 @@ class elasticsearch (
|
|||||||
ensure => latest,
|
ensure => latest,
|
||||||
source => "/tmp/elasticsearch-${version}.deb",
|
source => "/tmp/elasticsearch-${version}.deb",
|
||||||
provider => 'dpkg',
|
provider => 'dpkg',
|
||||||
subscribe => Exec['get_elasticsearch_deb_sha1'],
|
|
||||||
require => [
|
require => [
|
||||||
Package['openjdk-7-jre-headless'],
|
Package['openjdk-7-jre-headless'],
|
||||||
File['/etc/elasticsearch/elasticsearch.yml'],
|
File['/etc/elasticsearch/elasticsearch.yml'],
|
||||||
File['/etc/elasticsearch/default-mapping.json'],
|
File['/etc/elasticsearch/default-mapping.json'],
|
||||||
File['/etc/default/elasticsearch'],
|
File['/etc/default/elasticsearch'],
|
||||||
|
Archive["/tmp/elasticsearch-${version}.deb"],
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +79,6 @@ class elasticsearch (
|
|||||||
owner => 'root',
|
owner => 'root',
|
||||||
group => 'root',
|
group => 'root',
|
||||||
mode => '0644',
|
mode => '0644',
|
||||||
require => File['/etc/elasticsearch'],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
file { '/etc/elasticsearch/templates':
|
file { '/etc/elasticsearch/templates':
|
||||||
@ -103,7 +86,6 @@ class elasticsearch (
|
|||||||
owner => 'root',
|
owner => 'root',
|
||||||
group => 'root',
|
group => 'root',
|
||||||
mode => '0755',
|
mode => '0755',
|
||||||
require => File['/etc/elasticsearch'],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
file { '/etc/elasticsearch/default-mapping.json':
|
file { '/etc/elasticsearch/default-mapping.json':
|
||||||
@ -113,7 +95,6 @@ class elasticsearch (
|
|||||||
owner => 'root',
|
owner => 'root',
|
||||||
group => 'root',
|
group => 'root',
|
||||||
mode => '0644',
|
mode => '0644',
|
||||||
require => File['/etc/elasticsearch'],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
file { '/etc/default/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