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
13df76d3
Commit
13df76d3
authored
Mar 28, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #100 from sfromm/group-module
Remove support for membership from group module
parents
debd6fee
e851f754
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
58 deletions
+4
-58
examples/playbooks/group_commands.yml
+4
-7
library/group
+0
-51
No files found.
examples/playbooks/group_commands.yml
View file @
13df76d3
...
...
@@ -10,11 +10,8 @@
-
name
:
create a group
action
:
group name=tset
-
name
:
add a member to tset
action
:
group name=tset member=nobody memberstate=present
# You can only modify the group's gid
-
action
:
group name=tset gid=7777
-
name
:
remove member
action
:
group name=tset member=nobody memberstate=absent
-
name
:
remove group
action
:
group name=tset state=absent
# And finally remove the group
-
action
:
group name=tset state=absent
library/group
View file @
13df76d3
...
...
@@ -30,7 +30,6 @@ import sys
GROUPADD
=
"/usr/sbin/groupadd"
GROUPDEL
=
"/usr/sbin/groupdel"
GROUPMOD
=
"/usr/sbin/groupmod"
GPASSWD
=
"/usr/bin/gpasswd"
def
debug
(
msg
):
# ansible ignores stderr, so it's safe to use for debug
...
...
@@ -54,7 +53,6 @@ def add_group_info(kwargs):
kwargs
[
'state'
]
=
'present'
info
=
group_info
(
name
)
kwargs
[
'gid'
]
=
info
[
2
]
kwargs
[
'members'
]
=
info
[
3
]
else
:
kwargs
[
'state'
]
=
'absent'
return
kwargs
...
...
@@ -100,33 +98,6 @@ def group_mod(group, **kwargs):
else
:
return
False
def
group_has_member
(
group
,
member
):
if
not
group_exists
(
group
):
return
False
info
=
group_info
(
group
)
if
member
in
info
[
3
]:
return
True
else
:
return
False
def
group_add_member
(
group
,
member
):
cmd
=
[
GPASSWD
,
'-a'
,
member
,
group
]
debug
(
"Arguments to gpasswd:
%
s"
%
(
" "
.
join
(
cmd
)))
rc
=
subprocess
.
call
(
cmd
,
shell
=
False
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
if
rc
==
0
:
return
True
else
:
return
False
def
group_del_member
(
group
,
member
):
cmd
=
[
GPASSWD
,
'-d'
,
member
,
group
]
debug
(
"Arguments to gpasswd:
%
s"
%
(
" "
.
join
(
cmd
)))
rc
=
subprocess
.
call
(
cmd
,
shell
=
False
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
if
rc
==
0
:
return
True
else
:
return
False
def
group_exists
(
group
):
try
:
if
grp
.
getgrnam
(
group
):
...
...
@@ -160,11 +131,6 @@ if not os.path.exists(GROUPMOD):
GROUPDEL
=
"/sbin/groupmod"
else
:
fail_json
(
msg
=
"Cannot find groupmod"
)
if
not
os
.
path
.
exists
(
GPASSWD
):
if
os
.
path
.
exists
(
"/bin/gpasswd"
):
GROUPDEL
=
"/bin/gpasswd"
else
:
fail_json
(
msg
=
"Cannot find gpasswd"
)
if
len
(
sys
.
argv
)
==
2
and
os
.
path
.
exists
(
sys
.
argv
[
1
]):
argfile
=
sys
.
argv
[
1
]
...
...
@@ -186,15 +152,8 @@ state = params.get('state','present')
name
=
params
.
get
(
'name'
,
None
)
gid
=
params
.
get
(
'gid'
,
None
)
# ===========================================
# the following controls group membership
member
=
params
.
get
(
'member'
,
None
)
memberstate
=
params
.
get
(
'memberstate'
,
'present'
)
if
state
not
in
[
'present'
,
'absent'
]:
fail_json
(
msg
=
'invalid state'
)
if
memberstate
not
in
[
'present'
,
'absent'
]:
fail_json
(
msg
=
'invalid memberstate'
)
if
name
is
None
:
fail_json
(
msg
=
'name is required'
)
...
...
@@ -210,16 +169,6 @@ elif state == 'present':
else
:
changed
=
group_mod
(
name
,
gid
=
gid
)
if
member
is
not
None
:
if
memberstate
==
'present'
:
if
not
group_has_member
(
name
,
member
):
changed
=
group_add_member
(
name
,
member
)
elif
memberstate
==
'absent'
:
if
group_has_member
(
name
,
member
):
changed
=
group_del_member
(
name
,
member
)
else
:
fail_json
(
name
=
name
,
msg
=
'Unexpected position reached'
)
exit_json
(
name
=
name
,
changed
=
changed
)
fail_json
(
name
=
name
,
msg
=
'Unexpected position reached'
)
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