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
949f8b8f
Commit
949f8b8f
authored
12 years ago
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #571 from sfromm/group
Group module fixes
parents
36177cc9
3a5f2126
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
23 deletions
+34
-23
library/group
+34
-23
No files found.
library/group
View file @
949f8b8f
...
@@ -54,11 +54,10 @@ def add_group_info(kwargs):
...
@@ -54,11 +54,10 @@ def add_group_info(kwargs):
def
group_del
(
group
):
def
group_del
(
group
):
cmd
=
[
GROUPDEL
,
group
]
cmd
=
[
GROUPDEL
,
group
]
rc
=
subprocess
.
call
(
cmd
,
shell
=
False
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
p
=
subprocess
.
Popen
(
cmd
,
shell
=
False
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
if
rc
==
0
:
(
out
,
err
)
=
p
.
communicate
()
return
True
rc
=
p
.
returncode
else
:
return
(
rc
,
out
,
err
)
return
False
def
group_add
(
group
,
**
kwargs
):
def
group_add
(
group
,
**
kwargs
):
cmd
=
[
GROUPADD
]
cmd
=
[
GROUPADD
]
...
@@ -69,11 +68,10 @@ def group_add(group, **kwargs):
...
@@ -69,11 +68,10 @@ def group_add(group, **kwargs):
elif
key
==
'system'
and
kwargs
[
key
]
==
'yes'
:
elif
key
==
'system'
and
kwargs
[
key
]
==
'yes'
:
cmd
.
append
(
'-r'
)
cmd
.
append
(
'-r'
)
cmd
.
append
(
group
)
cmd
.
append
(
group
)
rc
=
subprocess
.
call
(
cmd
,
shell
=
False
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
p
=
subprocess
.
Popen
(
cmd
,
shell
=
False
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
if
rc
==
0
:
(
out
,
err
)
=
p
.
communicate
()
return
True
rc
=
p
.
returncode
else
:
return
(
rc
,
out
,
err
)
return
False
def
group_mod
(
group
,
**
kwargs
):
def
group_mod
(
group
,
**
kwargs
):
cmd
=
[
GROUPMOD
]
cmd
=
[
GROUPMOD
]
...
@@ -84,13 +82,12 @@ def group_mod(group, **kwargs):
...
@@ -84,13 +82,12 @@ def group_mod(group, **kwargs):
cmd
.
append
(
'-g'
)
cmd
.
append
(
'-g'
)
cmd
.
append
(
kwargs
[
key
])
cmd
.
append
(
kwargs
[
key
])
if
len
(
cmd
)
==
1
:
if
len
(
cmd
)
==
1
:
return
False
return
(
None
,
''
,
''
)
cmd
.
append
(
group
)
cmd
.
append
(
group
)
rc
=
subprocess
.
call
(
cmd
,
shell
=
False
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
p
=
subprocess
.
Popen
(
cmd
,
shell
=
False
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
if
rc
==
0
:
(
out
,
err
)
=
p
.
communicate
()
return
True
rc
=
p
.
returncode
else
:
return
(
rc
,
out
,
err
)
return
False
def
group_exists
(
group
):
def
group_exists
(
group
):
try
:
try
:
...
@@ -156,18 +153,32 @@ if system not in ['yes', 'no']:
...
@@ -156,18 +153,32 @@ if system not in ['yes', 'no']:
if
name
is
None
:
if
name
is
None
:
fail_json
(
msg
=
'name is required'
)
fail_json
(
msg
=
'name is required'
)
changed
=
False
rc
=
None
rc
=
0
out
=
''
err
=
''
result
=
{}
result
[
'name'
]
=
name
if
state
==
'absent'
:
if
state
==
'absent'
:
if
group_exists
(
name
):
if
group_exists
(
name
):
changed
=
group_del
(
name
)
(
rc
,
out
,
err
)
=
group_del
(
name
)
exit_json
(
name
=
name
,
changed
=
changed
)
if
rc
!=
0
:
fail_json
(
name
=
name
,
msg
=
err
)
elif
state
==
'present'
:
elif
state
==
'present'
:
if
not
group_exists
(
name
):
if
not
group_exists
(
name
):
changed
=
group_add
(
name
,
gid
=
gid
,
system
=
system
)
(
rc
,
out
,
err
)
=
group_add
(
name
,
gid
=
gid
,
system
=
system
)
else
:
else
:
changed
=
group_mod
(
name
,
gid
=
gid
)
(
rc
,
out
,
err
)
=
group_mod
(
name
,
gid
=
gid
)
exit_json
(
name
=
name
,
changed
=
changed
)
if
rc
is
not
None
and
rc
!=
0
:
fail_json
(
name
=
name
,
msg
=
err
)
if
rc
is
None
:
result
[
'changed'
]
=
False
else
:
result
[
'changed'
]
=
True
if
out
:
result
[
'stdout'
]
=
out
if
err
:
result
[
'stderr'
]
=
err
exit_json
(
**
result
)
fail_json
(
name
=
name
,
msg
=
'Unexpected position reached'
)
fail_json
(
name
=
name
,
msg
=
'Unexpected position reached'
)
This diff is collapsed.
Click to expand it.
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