From 87b271c7794fa7902bcf5811b913ccdf59e31577 Mon Sep 17 00:00:00 2001 From: Paul Otto Date: Thu, 11 Jun 2015 11:52:44 -0600 Subject: [PATCH 1/3] Add check for install_method of 'none'. Documented. --- README.markdown | 15 ++++++++ manifests/install.pp | 87 ++++++++++++++++++++++---------------------- 2 files changed, 59 insertions(+), 43 deletions(-) diff --git a/README.markdown b/README.markdown index 3525ee0d..9139ca4e 100644 --- a/README.markdown +++ b/README.markdown @@ -39,6 +39,21 @@ class { '::consul': On the agent(s): ```puppet class { '::consul': + config_hash => { + 'data_dir' => '/opt/consul', + 'datacenter' => 'east-aws', + 'log_level' => 'INFO', + 'node_name' => 'agent', + 'retry_join' => ['172.16.0.1'], + }ii +} +``` +Disable install and service components: +```puppet +class { '::consul': + install_method => 'none', + init_style => false, + manage_service => false, config_hash => { 'data_dir' => '/opt/consul', 'datacenter' => 'east-aws', diff --git a/manifests/install.pp b/manifests/install.pp index 01d4e81b..1e60803d 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -13,56 +13,57 @@ } } - if $consul::install_method == 'url' { - - if $::operatingsystem != 'darwin' { - ensure_packages(['unzip']) - } - staging::file { 'consul.zip': - source => $consul::real_download_url - } -> - staging::extract { 'consul.zip': - target => $consul::bin_dir, - creates => "${consul::bin_dir}/consul", - } -> - file { "${consul::bin_dir}/consul": - owner => 'root', - group => 0, # 0 instead of root because OS X uses "wheel". - mode => '0555', - } - - if ($consul::ui_dir and $consul::data_dir) { - file { "${consul::data_dir}/${consul::version}_web_ui": - ensure => 'directory', - owner => 'root', - group => 0, # 0 instead of root because OS X uses "wheel". - mode => '0755', - } -> - staging::deploy { 'consul_web_ui.zip': - source => $consul::real_ui_download_url, - target => "${consul::data_dir}/${consul::version}_web_ui", - creates => "${consul::data_dir}/${consul::version}_web_ui/dist", + case $consul::install_method { + 'url': { + if $::operatingsystem != 'darwin' { + ensure_packages(['unzip']) } - file { $consul::ui_dir: - ensure => 'symlink', - target => "${consul::data_dir}/${consul::version}_web_ui/dist", + staging::file { 'consul.zip': + source => $consul::real_download_url + } -> + staging::extract { 'consul.zip': + target => $consul::bin_dir, + creates => "${consul::bin_dir}/consul", + } -> + file { "${consul::bin_dir}/consul": + owner => 'root', + group => 0, # 0 instead of root because OS X uses "wheel". + mode => '0555', } - } - - } elsif $consul::install_method == 'package' { - package { $consul::package_name: - ensure => $consul::package_ensure, + if ($consul::ui_dir and $consul::data_dir) { + file { "${consul::data_dir}/${consul::version}_web_ui": + ensure => 'directory', + owner => 'root', + group => 0, # 0 instead of root because OS X uses "wheel". + mode => '0755', + } -> + staging::deploy { 'consul_web_ui.zip': + source => $consul::real_ui_download_url, + target => "${consul::data_dir}/${consul::version}_web_ui", + creates => "${consul::data_dir}/${consul::version}_web_ui/dist", + } + file { $consul::ui_dir: + ensure => 'symlink', + target => "${consul::data_dir}/${consul::version}_web_ui/dist", + } + } } + 'package': { + package { $consul::package_name: + ensure => $consul::package_ensure, + } - if $consul::ui_dir { - package { $consul::ui_package_name: - ensure => $consul::ui_package_ensure, + if $consul::ui_dir { + package { $consul::ui_package_name: + ensure => $consul::ui_package_ensure, + } } } - - } else { - fail("The provided install method ${consul::install_method} is invalid") + 'none': {} + default: { + fail("The provided install method ${consul::install_method} is invalid") + } } if $consul::manage_user { From f452e5709a67149a328dfb9cfe77ae55de84dec4 Mon Sep 17 00:00:00 2001 From: Paul Otto Date: Thu, 11 Jun 2015 16:55:33 -0600 Subject: [PATCH 2/3] Add unit test for install_method 'none' --- spec/classes/init_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 02777f9a..4034bcdb 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -110,6 +110,16 @@ it { should contain_package('custom_consul_ui_package').with(:ensure => 'specific_ui_release') } end + context 'When requesting to not to install' do + let(:params) {{ + :install_method => 'none' + }} + it { should_not contain_package('consul') } + it { should_not contain_package('consul_ui') } + it { should_not contain_staging__file('consul.zip') } + it { should_not contain_staging__file('consul_web_ui.zip') } + end + context "When installing UI via URL by default" do let(:params) {{ :config_hash => { From c16ff84bb7090dff648da74bff4dd65a3aa28a86 Mon Sep 17 00:00:00 2001 From: Paul Otto Date: Fri, 12 Jun 2015 06:47:32 -0600 Subject: [PATCH 3/3] Updated inline docstring for $install_method. --- manifests/init.pp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/manifests/init.pp b/manifests/init.pp index 1f11c05c..bbcc6d67 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -11,7 +11,9 @@ # Use this to populate the JSON config file for consul. # # [*install_method*] -# Defaults to `url` but can be `package` if you want to install via a system package. +# Valid strings: `package` - install via system package +# `url` - download and extract from a url. Defaults to `url`. +# `none` - disable install. # # [*package_name*] # Only valid when the install_method == package. Defaults to `consul`.