Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make consul::install optional #135

Merged
merged 3 commits into from
Jun 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 3 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
87 changes: 44 additions & 43 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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': {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The readme is good for the full example, but can you update the inline docstring on init.pp:13?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about that, I overlooked the docstring. Updated.

default: {
fail("The provided install method ${consul::install_method} is invalid")
}
}

if $consul::manage_user {
Expand Down
10 changes: 10 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down