camptocamp / puppet-accounts

11 stars 40 forks source link

Create user's group with custom GID before creating the user. #32

Closed johnzimm closed 8 years ago

johnzimm commented 8 years ago

Custom UID and GID are able to be specified for each user, but if the group doesn't already exist the user's new group is not created before attempting to create the new user.

You would recieve a message similar to the following:

Error: Could not create user example: Execution of '/sbin/useradd -g 66666 -d /home/example -p * -u 66666 -m example' returned 6: useradd: group '66666' does not exist
Error: /Stage[main]/Profiles::Base/Accounts::Account[@herp]/Accounts::Account[example]/User[example]/ensure: change from absent to present failed: Could not create user example: Execution of '/sbin/useradd -g 66666 -d /home/example -p * -u 66666 -m example' returned 6: useradd: group '66666' does not exist

Without specifying a custom GID Puppet will autorequire the group for the user and select the next available GID

This commit modifies account.pp to create the new group with custom GID prior to creating the user.

Deletion of the group, regardless of the GID, will happen automatically when the user is purged using this module.

NOTE: This is a rebase/cleanup of multiple commits from a pull request originally submitted by @mmckinst.

johnzimm commented 8 years ago

I will fix the errors being reported by CI and follow up on this PR hopefully this afternoon.

johnzimm commented 8 years ago

It looks like the build is failing to pull in the github_changelog_generator....

Installing github_changelog_generator 1.11.4 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

Trying to run the bundle/rake commands on a local test environment is giving similar issues with bundle install.

johnzimm commented 8 years ago

Ok. Builds are passing again.

3 commits in this pull request. Two of them are related to failing builds.

Please review and let me know if anything additional needs to be corrected.

@mmckinst - please also take a look and make sure my rebase of your commits still captures your intent. It solves the problem I needed to set gid for in my own testing.

mmckinst commented 8 years ago

@johnzimm LGTM. I'll close my pull request in favor of this one. Squashing my commits and updating the PR slipped my mind, thanks for taking care of it.

johnzimm commented 8 years ago

Closing this PR and re-opening. I've rebased onto current master to get rid of the commits that are recently conflicting. I'm now getting a CI error with the following for just ruby 1.8.7 which doesn't immediately make sense to me.

[0K$ ruby --version
ruby 1.8.7 (2013-06-27 patchlevel 374) [x86_64-linux]
$ rvm --version
rvm 1.26.10 (latest-minor) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
$ bundle --version
Bundler version 1.7.12
$ gem --version
2.4.5
travis_fold:start:install.bundler
travis_time:start:062f19a8
$ bundle install --without system_tests --path=${BUNDLE_PATH:-vendor/bundle}
Fetching gem metadata from https://rubygems.org/..........
Resolving dependencies...

Gem::InstallError: rake requires Ruby version >= 1.9.3.
An error occurred while installing rake (11.1.1), and Bundler cannot continue.
Make sure that `gem install rake -v '11.1.1'` succeeds before bundling.

The command "eval bundle install --without system_tests --path=${BUNDLE_PATH:-vendor/bundle}" failed. Retrying, 2 of 3.

Fetching gem metadata from https://rubygems.org/..........
Resolving dependencies...

Gem::InstallError: rake requires Ruby version >= 1.9.3.
An error occurred while installing rake (11.1.1), and Bundler cannot continue.
Make sure that `gem install rake -v '11.1.1'` succeeds before bundling.

The command "eval bundle install --without system_tests --path=${BUNDLE_PATH:-vendor/bundle}" failed. Retrying, 3 of 3.

Closing and reopening to rerun the build just to make sure.

mmckinst commented 8 years ago

I saw the same bug with another project. This commit fixed it: https://github.com/theforeman/puppet-puppet/commit/ea3e94a27e6c97cc034cb0e82e26b0c9b7d11331