dev/provisioning/modules/elasticsearch/manifests/repo.pp
changeset 406 cf0f23803a53
parent 28 b0b56e0f8c7f
equal deleted inserted replaced
405:f239c8c5bb94 406:cf0f23803a53
    24 # * Richard Pijnenburg <mailto:richard.pijnenburg@elasticsearch.com>
    24 # * Richard Pijnenburg <mailto:richard.pijnenburg@elasticsearch.com>
    25 #
    25 #
    26 class elasticsearch::repo {
    26 class elasticsearch::repo {
    27 
    27 
    28   Exec {
    28   Exec {
    29     path      => [ '/bin', '/usr/bin', '/usr/local/bin' ],
    29     path => [ '/bin', '/usr/bin', '/usr/local/bin' ],
    30     cwd       => '/',
    30     cwd  => '/',
       
    31   }
       
    32 
       
    33   if $elasticsearch::ensure == 'present' {
       
    34     if versioncmp($elasticsearch::repo_version, '5.0') >= 0 {
       
    35       $_repo_url = 'https://artifacts.elastic.co/packages'
       
    36       case $::osfamily {
       
    37         'Debian': {
       
    38           $_repo_path = 'apt'
       
    39         }
       
    40         default: {
       
    41           $_repo_path = 'yum'
       
    42         }
       
    43       }
       
    44     } else {
       
    45       $_repo_url = 'http://packages.elastic.co/elasticsearch'
       
    46       case $::osfamily {
       
    47         'Debian': {
       
    48           $_repo_path = 'debian'
       
    49         }
       
    50         default: {
       
    51           $_repo_path = 'centos'
       
    52         }
       
    53       }
       
    54     }
       
    55 
       
    56     $_baseurl = "${_repo_url}/${elasticsearch::repo_version}/${_repo_path}"
       
    57   } else {
       
    58     case $::osfamily {
       
    59       'Debian': {
       
    60         $_baseurl = undef
       
    61       }
       
    62       default: {
       
    63         $_baseurl = 'absent'
       
    64       }
       
    65     }
    31   }
    66   }
    32 
    67 
    33   case $::osfamily {
    68   case $::osfamily {
    34     'Debian': {
    69     'Debian': {
    35       include ::apt
    70       include ::apt
    36       Class['apt::update'] -> Package[$elasticsearch::package_name]
    71       Class['apt::update'] -> Package[$elasticsearch::package_name]
    37 
    72 
    38       apt::source { 'elasticsearch':
    73       apt::source { 'elasticsearch':
    39         location    => "http://packages.elastic.co/elasticsearch/${elasticsearch::repo_version}/debian",
    74         ensure   => $elasticsearch::ensure,
    40         release     => 'stable',
    75         location => $_baseurl,
    41         repos       => 'main',
    76         release  => 'stable',
    42         key         => $::elasticsearch::repo_key_id,
    77         repos    => 'main',
    43         key_source  => $::elasticsearch::repo_key_source,
    78         key      => {
    44         include_src => false,
    79           'id'     => $::elasticsearch::repo_key_id,
       
    80           'source' => $::elasticsearch::repo_key_source,
       
    81         },
       
    82         include  => {
       
    83           'src' => false,
       
    84           'deb' => true,
       
    85         },
       
    86         pin      => $elasticsearch::repo_priority,
    45       }
    87       }
    46     }
    88     }
    47     'RedHat', 'Linux': {
    89     'RedHat', 'Linux': {
       
    90       # Versions prior to 3.5.1 have issues with this param
       
    91       # See: https://tickets.puppetlabs.com/browse/PUP-2163
       
    92       if versioncmp($::puppetversion, '3.5.1') >= 0 {
       
    93         Yumrepo['elasticsearch'] {
       
    94           ensure => $elasticsearch::ensure,
       
    95         }
       
    96       }
    48       yumrepo { 'elasticsearch':
    97       yumrepo { 'elasticsearch':
    49         descr    => 'elasticsearch repo',
    98         descr    => 'elasticsearch repo',
    50         baseurl  => "http://packages.elastic.co/elasticsearch/${elasticsearch::repo_version}/centos",
    99         baseurl  => $_baseurl,
    51         gpgcheck => 1,
   100         gpgcheck => 1,
    52         gpgkey   => $::elasticsearch::repo_key_source,
   101         gpgkey   => $::elasticsearch::repo_key_source,
    53         enabled  => 1,
   102         enabled  => 1,
       
   103         proxy    => $::elasticsearch::repo_proxy,
       
   104         priority => $elasticsearch::repo_priority,
       
   105       } ~>
       
   106       exec { 'elasticsearch_yumrepo_yum_clean':
       
   107         command     => 'yum clean metadata expire-cache --disablerepo="*" --enablerepo="elasticsearch"',
       
   108         refreshonly => true,
       
   109         returns     => [0, 1],
    54       }
   110       }
    55     }
   111     }
    56     'Suse': {
   112     'Suse': {
       
   113       if $::operatingsystem == 'SLES' and versioncmp($::operatingsystemmajrelease, '11') <= 0 {
       
   114         # Older versions of SLES do not ship with rpmkeys
       
   115         $_import_cmd = "rpm --import ${::elasticsearch::repo_key_source}"
       
   116       } else {
       
   117         $_import_cmd = "rpmkeys --import ${::elasticsearch::repo_key_source}"
       
   118       }
       
   119 
    57       exec { 'elasticsearch_suse_import_gpg':
   120       exec { 'elasticsearch_suse_import_gpg':
    58         command => "rpmkeys --import ${::elasticsearch::repo_key_source}",
   121         command => $_import_cmd,
    59         unless  => "test $(rpm -qa gpg-pubkey | grep -i '${::elasticsearch::repo_key_id}' | wc -l) -eq 1 ",
   122         unless  =>
    60         notify  => [ Zypprepo['elasticsearch'] ],
   123           "test $(rpm -qa gpg-pubkey | grep -i 'D88E42B4' | wc -l) -eq 1",
       
   124         notify  => Zypprepo['elasticsearch'],
    61       }
   125       }
    62 
   126 
    63       zypprepo { 'elasticsearch':
   127       zypprepo { 'elasticsearch':
    64         baseurl     => "http://packages.elastic.co/elasticsearch/${elasticsearch::repo_version}/centos",
   128         baseurl     => $_baseurl,
    65         enabled     => 1,
   129         enabled     => 1,
    66         autorefresh => 1,
   130         autorefresh => 1,
    67         name        => 'elasticsearch',
   131         name        => 'elasticsearch',
    68         gpgcheck    => 1,
   132         gpgcheck    => 1,
    69         gpgkey      => $::elasticsearch::repo_key_source,
   133         gpgkey      => $::elasticsearch::repo_key_source,
    70         type        => 'yum',
   134         type        => 'yum',
       
   135       } ~>
       
   136       exec { 'elasticsearch_zypper_refresh_elasticsearch':
       
   137         command     => 'zypper refresh elasticsearch',
       
   138         refreshonly => true,
    71       }
   139       }
    72     }
   140     }
    73     default: {
   141     default: {
    74       fail("\"${module_name}\" provides no repository information for OSfamily \"${::osfamily}\"")
   142       fail("\"${module_name}\" provides no repository information for OSfamily \"${::osfamily}\"")
    75     }
   143     }
    76   }
   144   }
    77 
   145 
    78   # Package pinning
       
    79 
       
    80     case $::osfamily {
       
    81       'Debian': {
       
    82         include ::apt
       
    83 
       
    84         if ($elasticsearch::package_pin == true and $elasticsearch::version != false) {
       
    85           apt::pin { $elasticsearch::package_name:
       
    86             ensure   => 'present',
       
    87             packages => $elasticsearch::package_name,
       
    88             version  => $elasticsearch::version,
       
    89             priority => 1000,
       
    90           }
       
    91         }
       
    92 
       
    93       }
       
    94       'RedHat', 'Linux': {
       
    95 
       
    96         if ($elasticsearch::package_pin == true and $elasticsearch::version != false) {
       
    97           yum::versionlock { "0:elasticsearch-${elasticsearch::pkg_version}.noarch":
       
    98             ensure => 'present',
       
    99           }
       
   100         }
       
   101       }
       
   102       default: {
       
   103         warning("Unable to pin package for OSfamily \"${::osfamily}\".")
       
   104       }
       
   105     }
       
   106 }
   146 }