Module: Prepper::Tools::Users
- Included in:
- Package
- Defined in:
- lib/prepper/tools/users.rb
Overview
user management related helpers
Instance Method Summary collapse
-
#add_user(username, opts = {}) ⇒ Object
add a user to the host.
-
#has_user?(username, opts = {}) ⇒ Boolean
returns a verifier command to check if a user exists.
Instance Method Details
#add_user(username, opts = {}) ⇒ Object
add a user to the host
9 10 11 12 |
# File 'lib/prepper/tools/users.rb', line 9 def add_user(username, opts = {}) opts[:flags] << ' --gecos ,,,' @commands << Command.new("adduser #{username} #{opts[:flags]}", sudo: true, verifier: has_user?(username)) end |
#has_user?(username, opts = {}) ⇒ Boolean
returns a verifier command to check if a user exists
18 19 20 21 22 23 24 25 |
# File 'lib/prepper/tools/users.rb', line 18 def has_user?(username, opts = {}) if opts[:in_group] command = "id -nG #{username} | xargs -n1 echo | grep #{opts[:in_group]}" else command = "id #{username}" end Command.new(command, sudo: true) end |