Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
3235da07
Commit
3235da07
authored
Jul 10, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #568 from sfromm/user
User modules fixes
parents
8bb41bc6
09f025b7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
32 deletions
+46
-32
library/user
+46
-32
No files found.
library/user
View file @
3235da07
...
...
@@ -75,11 +75,10 @@ def user_del(user, **kwargs):
elif
key
==
'remove'
and
kwargs
[
key
]:
cmd
.
append
(
'-r'
)
cmd
.
append
(
user
)
rc
=
subprocess
.
call
(
cmd
,
shell
=
False
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
if
rc
==
0
:
return
True
else
:
return
False
p
=
subprocess
.
Popen
(
cmd
,
shell
=
False
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
(
out
,
err
)
=
p
.
communicate
()
rc
=
p
.
returncode
return
(
rc
,
out
,
err
)
def
user_add
(
user
,
**
kwargs
):
cmd
=
[
USERADD
]
...
...
@@ -119,11 +118,10 @@ def user_add(user, **kwargs):
elif
key
==
'system'
and
kwargs
[
key
]
==
'yes'
:
cmd
.
append
(
'-r'
)
cmd
.
append
(
user
)
rc
=
subprocess
.
call
(
cmd
,
shell
=
False
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
if
rc
==
0
:
return
True
else
:
return
False
p
=
subprocess
.
Popen
(
cmd
,
shell
=
False
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
(
out
,
err
)
=
p
.
communicate
()
rc
=
p
.
returncode
return
(
rc
,
out
,
err
)
"""
Without spwd, we would have to resort to reading /etc/shadow
...
...
@@ -184,13 +182,12 @@ def user_mod(user, **kwargs):
cmd
.
append
(
kwargs
[
key
])
# skip if no changes to be made
if
len
(
cmd
)
==
1
:
return
False
return
(
None
,
''
,
''
)
cmd
.
append
(
user
)
rc
=
subprocess
.
call
(
cmd
,
shell
=
False
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
if
rc
==
0
:
return
True
else
:
return
False
p
=
subprocess
.
Popen
(
cmd
,
shell
=
False
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
(
out
,
err
)
=
p
.
communicate
()
rc
=
p
.
returncode
return
(
rc
,
out
,
err
)
def
group_exists
(
group
):
try
:
...
...
@@ -313,27 +310,44 @@ if append not in [ 'yes', 'no' ]:
if
name
is
None
:
fail_json
(
msg
=
'name is required'
)
changed
=
False
result
=
{}
rc
=
0
out
=
''
err
=
''
result
[
'name'
]
=
name
if
state
==
'absent'
:
if
user_exists
(
name
):
changed
=
user_del
(
name
,
force
=
force
,
remove
=
remove
)
exit_json
(
name
=
name
,
changed
=
changed
,
force
=
force
,
remove
=
remove
)
if
not
user_exists
(
name
):
result
[
'changed'
]
=
False
else
:
(
rc
,
out
,
err
)
=
user_del
(
name
,
force
=
force
,
remove
=
remove
)
if
rc
!=
0
:
fail_json
(
name
=
name
,
msg
=
err
)
else
:
result
[
'changed'
]
=
True
result
[
'force'
]
=
force
result
[
'remove'
]
=
remove
elif
state
==
'present'
:
if
not
user_exists
(
name
):
changed
=
user_add
(
name
,
uid
=
uid
,
group
=
group
,
groups
=
groups
,
comment
=
comment
,
home
=
home
,
shell
=
shell
,
password
=
password
,
createhome
=
createhome
,
system
=
system
)
(
rc
,
out
,
err
)
=
user_add
(
name
,
uid
=
uid
,
group
=
group
,
groups
=
groups
,
comment
=
comment
,
home
=
home
,
shell
=
shell
,
password
=
password
,
createhome
=
createhome
,
system
=
system
)
else
:
changed
=
user_mod
(
name
,
uid
=
uid
,
group
=
group
,
groups
=
groups
,
comment
=
comment
,
home
=
home
,
shell
=
shell
,
password
=
password
,
append
=
append
)
if
password
is
not
None
:
exit_json
(
name
=
name
,
changed
=
changed
,
password
=
"XXXXXXXX"
)
(
rc
,
out
,
err
)
=
user_mod
(
name
,
uid
=
uid
,
group
=
group
,
groups
=
groups
,
comment
=
comment
,
home
=
home
,
shell
=
shell
,
password
=
password
,
append
=
append
)
if
rc
is
not
None
and
rc
!=
0
:
fail_json
(
name
=
name
,
msg
=
err
)
if
rc
is
None
:
result
[
'changed'
]
=
False
else
:
exit_json
(
name
=
name
,
changed
=
changed
)
result
[
'changed'
]
=
True
if
password
is
not
None
:
result
[
'password'
]
=
'NOTLOGGINGPASSWORD'
fail_json
(
name
=
name
,
msg
=
'Unexpected position reached'
)
if
out
:
result
[
'stdout'
]
=
out
if
err
:
result
[
'stderr'
]
=
err
exit_json
(
**
result
)
sys
.
exit
(
0
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment