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 group ID #677

Merged
merged 2 commits 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
27 changes: 27 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ 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)
* [`gid`](#-consul--gid)

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

Expand Down Expand Up @@ -592,6 +595,30 @@ 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`

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

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

the ID for the consul group

Default value: `undef`

## Defined types

### <a name="consul--check"></a>`consul::check`
Expand Down
6 changes: 6 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
# 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
# @param gid the ID for the consul group
#
# @example simple consul setup
# class { 'consul':
Expand Down Expand Up @@ -142,6 +145,9 @@
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,
Optional[Integer[1]] $gid = undef,
) inherits consul::params {
$real_download_url = pick(
$download_url,
Expand Down
13 changes: 8 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 All @@ -117,6 +119,7 @@
group { $consul::group_real:
ensure => 'present',
system => true,
gid => $consul::gid,
}
}
}
15 changes: 14 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,19 @@
it { is_expected.to contain_user('consul').with(ensure: :present).without_home }
end

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

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

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