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
23cbdba6
Commit
23cbdba6
authored
Oct 16, 2013
by
James Tanner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #4350 Create homedirectory if create=yes and directory is missing
parent
8a3f222d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
1 deletions
+35
-1
library/system/user
+35
-1
No files found.
library/system/user
View file @
23cbdba6
...
...
@@ -92,7 +92,8 @@ options:
choices: [ "yes", "no" ]
description:
- Unless set to C(no), a home directory will be made for the user
when the account is created.
when the account is created or if the home directory does not
exist.
system:
required: false
default: "no"
...
...
@@ -563,6 +564,32 @@ class User(object):
# by default we use the modify_user_usermod method
return
self
.
modify_user_usermod
()
def
create_homedir
(
self
,
path
):
if
not
os
.
path
.
exists
(
path
):
# use /etc/skel if possible
if
os
.
path
.
exists
(
'/etc/skel'
):
try
:
shutil
.
copytree
(
'/etc/skel'
,
path
,
symlinks
=
True
)
except
OSError
,
e
:
self
.
module
.
exit_json
(
failed
=
True
,
msg
=
"
%
s"
%
e
)
else
:
try
:
os
.
makedirs
(
path
)
except
OSError
,
e
:
self
.
module
.
exit_json
(
failed
=
True
,
msg
=
"
%
s"
%
e
)
def
chown_homedir
(
self
,
uid
,
gid
,
path
):
try
:
os
.
chown
(
path
,
uid
,
gid
)
for
root
,
dirs
,
files
in
os
.
walk
(
path
):
for
d
in
dirs
:
os
.
chown
(
path
,
uid
,
gid
)
for
f
in
files
:
os
.
chown
(
os
.
path
.
join
(
root
,
f
),
uid
,
gid
)
except
OSError
,
e
:
self
.
module
.
exit_json
(
failed
=
True
,
msg
=
"
%
s"
%
e
)
# ===========================================
class
FreeBsdUser
(
User
):
...
...
@@ -1485,6 +1512,13 @@ def main():
result
[
'ssh_key_file'
]
=
user
.
get_ssh_key_path
()
result
[
'ssh_public_key'
]
=
user
.
get_ssh_public_key
()
# handle missing homedirs
if
not
os
.
path
.
exists
(
user
.
home
)
and
user
.
createhome
:
if
not
module
.
check_mode
:
info
=
user
.
user_info
()
user
.
create_homedir
(
user
.
home
)
user
.
chown_homedir
(
info
[
2
],
info
[
3
],
user
.
home
)
result
[
'changed'
]
=
True
module
.
exit_json
(
**
result
)
...
...
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