Skip to content

Commit

Permalink
Add initial_admin_password parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
crazymind1337 committed Feb 26, 2024
1 parent acabb95 commit 7eea8f9
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 6 deletions.
7 changes: 7 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ The following parameters are available in the `opensearch` class:
* [`package_directory`](#-opensearch--package_directory)
* [`pin_package`](#-opensearch--pin_package)
* [`apt_pin_priority`](#-opensearch--apt_pin_priority)
* [`initial_admin_password`](#-opensearch--initial_admin_password)
* [`manage_config`](#-opensearch--manage_config)
* [`use_default_settings`](#-opensearch--use_default_settings)
* [`default_settings`](#-opensearch--default_settings)
Expand Down Expand Up @@ -157,6 +158,12 @@ The priority for apt::pin of the opensearch package.

Default value: `1001`

##### <a name="-opensearch--initial_admin_password"></a>`initial_admin_password`

Data type: `String[1]`

Password for intial installation of the package.

##### <a name="-opensearch--manage_config"></a>`manage_config`

Data type: `Boolean`
Expand Down
3 changes: 3 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
# Whether to enable the `apt::pin` or `yum::versionlock` for the package.
# @param apt_pin_priority
# The priority for apt::pin of the opensearch package.
# @param initial_admin_password
# Password for intial installation of the package.
#
# @param manage_config
# Whether to manage the configuration.
Expand Down Expand Up @@ -116,6 +118,7 @@
Enum['x64', 'arm64'] $package_architecture,
Enum['dpkg', 'rpm'] $package_provider,
Hash $default_settings,
String[1] $initial_admin_password,

##
## version
Expand Down
6 changes: 6 additions & 0 deletions manifests/install/package.pp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,15 @@
}
}

exec { 'set_initial_password_environment':
path => $facts['path'],
command => "export OPENSEARCH_INITIAL_ADMIN_PASSWORD=${opensearch::initial_admin_password}"

Check warning on line 66 in manifests/install/package.pp

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

missing trailing comma after last element (check: trailing_comma)
}

package { 'opensearch':
ensure => $ensure,
provider => $provider,
source => $source,
require => Exec['set_initial_password_environment'],
}
}
13 changes: 9 additions & 4 deletions spec/acceptance/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
context 'default parameter' do
it_behaves_like 'an idempotent resource' do
let(:manifest) do
'include opensearch'
<<~PP
class { 'opensearch':
initial_admin_password => 'some_random_password',
}
PP
end
end

Expand Down Expand Up @@ -49,9 +53,10 @@
let(:manifest) do
<<~PP
class { 'opensearch':
version => '2.9.0',
package_source => 'archive',
settings => {
version => '2.9.0',
package_source => 'archive',
initial_admin_password => 'some_random_password',
settings => {
# When installing from an archive, the demo certificates are not
# installed by default.
'plugins.security.disabled' => true,
Expand Down
10 changes: 9 additions & 1 deletion spec/shared_examples/install_package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,21 @@
end
end

it {
is_expected.to contain_exec('set_initial_password_environment').with(
{
'command' => "export OPENSEARCH_INITIAL_ADMIN_PASSWORD=#{parameter['initial_admin_password']}"
}
)
}

it {
is_expected.to contain_package('opensearch').with(
{
'ensure' => ensure_value,
'provider' => provider,
'source' => source,
}
)
).that_requires('Exec[set_initial_password_environment]')
}
end
10 changes: 9 additions & 1 deletion spec/spec_helper_local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,44 @@
require 'helper/get_defaults'

TESTS = {
'with default value' => {},
'with default value' => {
'initial_admin_password' => 'some_random_password',
},
'with installation via archive and version 2.6.0' => {
'initial_admin_password' => 'some_random_password',
'version' => '2.6.0',
'package_source' => 'archive',
},
'with installation via download and version 2.6.0' => {
'initial_admin_password' => 'some_random_password',
'version' => '2.6.0',
'package_source' => 'download',
},
'with some settings given' => {
'initial_admin_password' => 'some_random_password',
'settings' => {
'http_max_content_length' => 10,
'indices_queries_cache_size' => 10,
},
},
'with some settings given and no default settings' => {
'initial_admin_password' => 'some_random_password',
'use_default_settings' => false,
'settings' => {
'http_max_content_length' => 10,
'indices_queries_cache_size' => 10,
},
},
'with some jvm gc settings' => {
'initial_admin_password' => 'some_random_password',
'jvm_gc_settings' => [
'-XX:+UseG1GC',
'-XX:G1ReservePercent=50',
'-XX:InitiatingHeapOccupancyPercent=50',
],
},
'with only jvm gc logging settings given' => {
'initial_admin_password' => 'some_random_password',
'use_default_jvm_gc_logging_settings' => false,
'jvm_gc_logging_settings' => [
'-XX:+PrintGCApplicationStoppedTime',
Expand Down

0 comments on commit 7eea8f9

Please sign in to comment.