check for pwd on linux and BSD user exec mods

This commit is contained in:
Justin Findlay 2015-08-13 13:11:28 -06:00
parent 679dc089c0
commit 26f5b466f5
2 changed files with 8 additions and 5 deletions

View file

@ -6,8 +6,9 @@ Manage users with the useradd command
# Import python libs
try:
import pwd
HAS_PWD = True
except ImportError:
pass
HAS_PWD = False
import logging
import copy
@ -26,7 +27,9 @@ def __virtual__():
'''
Set the user module if the kernel is FreeBSD
'''
return __virtualname__ if __grains__['kernel'] == 'FreeBSD' else False
if HAS_PWD and __grains__['kernel'] == 'FreeBSD':
return __virtualname__
return False
def _get_gecos(name):

View file

@ -9,8 +9,9 @@ import re
try:
import pwd
HAS_PWD = True
except ImportError:
pass
HAS_PWD = False
import logging
import copy
@ -32,10 +33,9 @@ __virtualname__ = 'user'
def __virtual__():
'''
Set the user module if the kernel is Linux, OpenBSD or NetBSD
and remove some of the functionality on OS X
'''
if __grains__['kernel'] in ('Linux', 'OpenBSD', 'NetBSD'):
if HAS_PWD and __grains__['kernel'] in ('Linux', 'OpenBSD', 'NetBSD'):
return __virtualname__
return False