summaryrefslogtreecommitdiff
path: root/lib/chef/provider
diff options
context:
space:
mode:
authorskippy <jonathan.yates.jones@gmail.com>2019-11-17 05:50:17 +0000
committerskippy <jonathan.yates.jones@gmail.com>2019-11-17 05:50:17 +0000
commit768d0f18a091622902e7eefcb6b2f68bc17d3145 (patch)
treea2ee268498da6375591fa23770fab8f587767031 /lib/chef/provider
parenta846c6ae160829ff9dd46d9e61137d624e729ea0 (diff)
downloadchef-768d0f18a091622902e7eefcb6b2f68bc17d3145.tar.gz
Modifed linux_user resource to add an additional 'returns' field to each action method s
hell_out reference. This fixes an issue related to certain commands returning non-0 exit codes but still functioning as exptected Signed-off-by: Jonathan Jones <gitmaster@thespooky.house>
Diffstat (limited to 'lib/chef/provider')
-rw-r--r--lib/chef/provider/user/linux.rb23
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/chef/provider/user/linux.rb b/lib/chef/provider/user/linux.rb
index d27dbcabd4..58d14e40e2 100644
--- a/lib/chef/provider/user/linux.rb
+++ b/lib/chef/provider/user/linux.rb
@@ -24,23 +24,23 @@ class Chef
provides :user, os: "linux"
def create_user
- shell_out!("useradd", universal_options, useradd_options, new_resource.username)
+ shell_out!("useradd", universal_options, useradd_options, new_resource.username, returns: return_codes)
end
def manage_user
- shell_out!("usermod", universal_options, usermod_options, new_resource.username)
+ shell_out!("usermod", universal_options, usermod_options, new_resource.username, returns: return_codes)
end
def remove_user
- shell_out!("userdel", userdel_options, new_resource.username)
+ shell_out!("userdel", userdel_options, new_resource.username, returns: return_codes)
end
def lock_user
- shell_out!("usermod", "-L", new_resource.username)
+ shell_out!("usermod", "-L", new_resource.username, returns: return_codes)
end
def unlock_user
- shell_out!("usermod", "-U", new_resource.username)
+ shell_out!("usermod", "-U", new_resource.username, returns: return_codes)
end
# common to usermod and useradd
@@ -56,6 +56,19 @@ class Chef
opts
end
+ def return_codes
+ ret_codes = [0]
+ if updating_home?
+ if new_resource.manage_home
+ home_dir_exist = shell_out!("test", "-d" new_resource.home, returns [1])
+ if home_dir_exist.error?
+ opts << 12
+ end
+ end
+ end
+ ret_codes.to_s
+ end
+
def usermod_options
opts = []
opts += [ "-u", new_resource.uid ] if new_resource.non_unique