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
dd7f7d55
Commit
dd7f7d55
authored
Jun 18, 2013
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'file_hard' of
git://github.com/bcoca/ansible
into devel
Conflicts: library/files/file
parents
e90d0be1
9e6a584c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
11 deletions
+22
-11
library/files/file
+22
-11
No files found.
library/files/file
View file @
dd7f7d55
...
@@ -48,12 +48,12 @@ options:
...
@@ -48,12 +48,12 @@ options:
- If C(directory), all immediate subdirectories will be created if they
- If C(directory), all immediate subdirectories will be created if they
do not exist. If C(file), the file will NOT be created if it does not
do not exist. If C(file), the file will NOT be created if it does not
exist, see the M(copy) or M(template) module if you want that behavior.
exist, see the M(copy) or M(template) module if you want that behavior.
If C(link), the symbolic link will be created or changed.
If C(absent),
If C(link), the symbolic link will be created or changed.
Use C(hard)
directories will be recursively deleted, and files or symlinks will be
for hardlinks. If C(absent), directories will be recursively deleted,
unlinked.
and files or symlinks will be
unlinked.
required: false
required: false
default: file
default: file
choices: [ file, link, directory, absent ]
choices: [ file, link, directory,
hard,
absent ]
mode:
mode:
required: false
required: false
default: null
default: null
...
@@ -131,6 +131,15 @@ EXAMPLES = '''
...
@@ -131,6 +131,15 @@ EXAMPLES = '''
- file: src=/file/to/link/to dest=/path/to/symlink owner=foo group=foo state=link
- file: src=/file/to/link/to dest=/path/to/symlink owner=foo group=foo state=link
'''
'''
def
dolink
(
src
,
path
,
state
,
module
):
try
:
if
state
==
'hard'
:
os
.
link
(
src
,
path
)
else
:
os
.
symlink
(
src
,
path
)
except
OSError
,
e
:
module
.
fail_json
(
path
=
path
,
msg
=
'Error while linking:
%
s'
%
str
(
e
))
def
main
():
def
main
():
# FIXME: pass this around, should not use global
# FIXME: pass this around, should not use global
...
@@ -138,7 +147,7 @@ def main():
...
@@ -138,7 +147,7 @@ def main():
module
=
AnsibleModule
(
module
=
AnsibleModule
(
argument_spec
=
dict
(
argument_spec
=
dict
(
state
=
dict
(
choices
=
[
'file'
,
'directory'
,
'link'
,
'absent'
],
default
=
'file'
),
state
=
dict
(
choices
=
[
'file'
,
'directory'
,
'link'
,
'
hard'
,
'
absent'
],
default
=
'file'
),
path
=
dict
(
aliases
=
[
'dest'
,
'name'
],
required
=
True
),
path
=
dict
(
aliases
=
[
'dest'
,
'name'
],
required
=
True
),
recurse
=
dict
(
default
=
'no'
,
type
=
'bool'
),
recurse
=
dict
(
default
=
'no'
,
type
=
'bool'
),
diff_peek
=
dict
(
default
=
None
),
diff_peek
=
dict
(
default
=
None
),
...
@@ -177,8 +186,8 @@ def main():
...
@@ -177,8 +186,8 @@ def main():
file_args
=
module
.
load_file_common_arguments
(
params
)
file_args
=
module
.
load_file_common_arguments
(
params
)
if
state
==
'link'
and
(
src
is
None
or
path
is
None
):
if
state
in
[
'link'
,
'hard'
]
and
(
src
is
None
or
path
is
None
):
module
.
fail_json
(
msg
=
'src and dest are required for
"link" state
'
)
module
.
fail_json
(
msg
=
'src and dest are required for
creating links
'
)
elif
path
is
None
:
elif
path
is
None
:
module
.
fail_json
(
msg
=
'path is required'
)
module
.
fail_json
(
msg
=
'path is required'
)
...
@@ -225,7 +234,7 @@ def main():
...
@@ -225,7 +234,7 @@ def main():
if
state
==
'file'
:
if
state
==
'file'
:
if
prev_state
!=
'file'
:
if
prev_state
!=
'file'
:
module
.
fail_json
(
path
=
path
,
msg
=
'file (
%
s) does not exist, use copy or template module to create'
%
path
)
module
.
fail_json
(
path
=
path
,
msg
=
'file (
%
s) does not exist, use copy or template module to create'
%
path
)
changed
=
module
.
set_file_attributes_if_different
(
file_args
,
changed
)
changed
=
module
.
set_file_attributes_if_different
(
file_args
,
changed
)
module
.
exit_json
(
path
=
path
,
changed
=
changed
)
module
.
exit_json
(
path
=
path
,
changed
=
changed
)
...
@@ -253,7 +262,7 @@ def main():
...
@@ -253,7 +262,7 @@ def main():
changed
=
module
.
set_file_attributes_if_different
(
tmp_file_args
,
changed
)
changed
=
module
.
set_file_attributes_if_different
(
tmp_file_args
,
changed
)
module
.
exit_json
(
path
=
path
,
changed
=
changed
)
module
.
exit_json
(
path
=
path
,
changed
=
changed
)
elif
state
==
'link'
:
elif
state
in
[
'link'
,
'hard'
]
:
if
os
.
path
.
isabs
(
src
):
if
os
.
path
.
isabs
(
src
):
abs_src
=
src
abs_src
=
src
...
@@ -265,7 +274,7 @@ def main():
...
@@ -265,7 +274,7 @@ def main():
if
prev_state
==
'absent'
:
if
prev_state
==
'absent'
:
if
module
.
check_mode
:
if
module
.
check_mode
:
module
.
exit_json
(
changed
=
True
)
module
.
exit_json
(
changed
=
True
)
os
.
symlink
(
src
,
path
)
dolink
(
src
,
path
,
state
,
module
)
changed
=
True
changed
=
True
elif
prev_state
==
'link'
:
elif
prev_state
==
'link'
:
old_src
=
os
.
readlink
(
path
)
old_src
=
os
.
readlink
(
path
)
...
@@ -275,8 +284,10 @@ def main():
...
@@ -275,8 +284,10 @@ def main():
if
module
.
check_mode
:
if
module
.
check_mode
:
module
.
exit_json
(
changed
=
True
)
module
.
exit_json
(
changed
=
True
)
os
.
unlink
(
path
)
os
.
unlink
(
path
)
os
.
symlink
(
src
,
path
)
dolink
(
src
,
path
,
state
,
module
)
changed
=
True
changed
=
True
elif
prev_state
==
'file'
:
module
.
fail_json
(
dest
=
path
,
src
=
src
,
msg
=
'Cannot link, file exists at destination'
)
else
:
else
:
module
.
fail_json
(
dest
=
path
,
src
=
src
,
msg
=
'unexpected position reached'
)
module
.
fail_json
(
dest
=
path
,
src
=
src
,
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