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

Add support for managing user ID and comment #676

Merged
merged 1 commit into from
Oct 30, 2024
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
18 changes: 18 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ The following parameters are available in the `consul` class:
* [`enable_beta_ui`](#-consul--enable_beta_ui)
* [`allow_binding_to_root_ports`](#-consul--allow_binding_to_root_ports)
* [`log_file`](#-consul--log_file)
* [`comment`](#-consul--comment)
* [`uid`](#-consul--uid)

##### <a name="-consul--acls"></a>`acls`

Expand Down Expand Up @@ -592,6 +594,22 @@ where should the log file be located

Default value: `'/var/log/consul'`

##### <a name="-consul--comment"></a>`comment`

Data type: `Optional[String[1]]`

the comment for the consul user, will be added to /etc/passwd

Default value: `undef`

##### <a name="-consul--uid"></a>`uid`

Data type: `Optional[Integer[1]]`

the ID for the consul user

Default value: `undef`

## Defined types

### <a name="consul--check"></a>`consul::check`
Expand Down
4 changes: 4 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
# You can enable it by setting this variable to true. Defaults to false
# @param allow_binding_to_root_ports enables CAP_NET_BIND_SERVICE if true. This is currently only implemented on systemd nodes
# @param log_file where should the log file be located
# @param comment the comment for the consul user, will be added to /etc/passwd
# @param uid the ID for the consul user
#
# @example simple consul setup
# class { 'consul':
Expand Down Expand Up @@ -142,6 +144,8 @@
Optional[String[1]] $shell = $consul::params::shell,
Boolean $enable_beta_ui = false,
Boolean $allow_binding_to_root_ports = false,
Optional[String[1]] $comment = undef,
Optional[Integer[1]] $uid = undef,
) inherits consul::params {
$real_download_url = pick(
$download_url,
Expand Down
12 changes: 7 additions & 5 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,13 @@
}

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

if ($consul::manage_group) and ($consul::install_method != 'docker' ) {
Expand Down
13 changes: 12 additions & 1 deletion spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
end

context 'By default, a user and group should be installed' do
it { is_expected.to contain_user('consul').with(ensure: :present) }
it { is_expected.to contain_user('consul').with(ensure: :present).without_uid.without_comment }
it { is_expected.to contain_group('consul').with(ensure: :present) }
end

Expand All @@ -256,6 +256,17 @@
it { is_expected.to contain_user('consul').with(ensure: :present).without_home }
end

context 'with uid and comment' do
let :params do
{
uid: 2,
comment: 'this is a comment',
}
end

it { is_expected.to contain_user('consul').with(ensure: :present).with_uid(2).with_comment('this is a comment') }
end

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