Skip to content

Commit

Permalink
Make home directory location setting optional
Browse files Browse the repository at this point in the history
  • Loading branch information
genebean committed May 18, 2021
1 parent 7d7c502 commit 365f4a4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -48,6 +48,7 @@ new versions of consul. Pin to the version that works for your setup!
- If installing from docker, you *must* ensure puppetlabs-docker_platform module is available.
- If installing on windows, you *must* install the `puppetlabs/powershell` module.
- Optionally installs a user to run it under
- *NOTE:* users enabling this and just starting with Consul should consider setting `manage_user_home_location` to `true`. It defaults to false for backwards compatibility.
- Installs a configuration file (/etc/consul/config.json)
- Manages the consul service via upstart, sysv, systemd, or nssm.
- Optionally installs the Web UI
Expand Down
7 changes: 7 additions & 0 deletions manifests/init.pp
Expand Up @@ -117,6 +117,12 @@
# [*manage_user*]
# Whether to create/manage the user that should own consul's configuration files.
#
# [*manage_user_home_location*]
# Whether to explicitly set the location of teh consul user's home directory when this modules
# manages the creation of the user. If the consul user already exists and this is enabled, puppet
# tries to change the consul user's home to the new location. This will cause the puppet run to
# fail if the consul service is currently running.
#
# [*manage_data_dir*]
# Whether to manage the consul storage data directory.
#
Expand Down Expand Up @@ -227,6 +233,7 @@
Boolean $manage_repo = $consul::params::manage_repo,
Boolean $manage_service = true,
Boolean $manage_user = $consul::params::manage_user,
Boolean $manage_user_home_location = false,
Boolean $manage_data_dir = true,
String[1] $os = $facts['kernel'].downcase,
String[1] $package_ensure = 'latest',
Expand Down
11 changes: 10 additions & 1 deletion manifests/install.pp
Expand Up @@ -87,12 +87,21 @@
}

if ($consul::manage_user) and ($consul::install_method != 'docker' ) {
# If the consul user already exists and this tries to change its home
# location the puppet run will fail if the consul service is currently
# running. This is a workaround for
# https://github.com/solarkennedy/puppet-consul/issues/559
$consul_user_home = $consul::manage_user_home_location ? {
true => $real_data_dir,
false => undef,
}

user { $consul::user_real:
ensure => 'present',
system => true,
groups => $consul::extra_groups,
shell => $consul::shell,
home => $real_data_dir,
home => $consul_user_home,
}

if ($consul::manage_group) and ($consul::install_method != 'docker' ) {
Expand Down
10 changes: 10 additions & 0 deletions spec/classes/init_spec.rb
Expand Up @@ -245,6 +245,16 @@
it { is_expected.to contain_group('consul').with(ensure: :present) }
end

context 'When the user home directory location is not managed, a user should be created without the home parameter' do
let(:params) do
{
manage_user_home_location: false,
}
end

it { is_expected.to contain_user('consul').with(ensure: :present).without_home }
end

context 'When data_dir is provided' do
let(:params) do
{
Expand Down

0 comments on commit 365f4a4

Please sign in to comment.