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
c9b6f0d0
Commit
c9b6f0d0
authored
Jun 30, 2013
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'files_force' of
git://github.com/rhaido/ansible
into devel
parents
be5386f9
bba19cb9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
3 deletions
+30
-3
library/files/file
+30
-3
No files found.
library/files/file
View file @
c9b6f0d0
...
...
@@ -120,6 +120,20 @@ options:
version_added: "1.1"
description:
- recursively set the specified file attributes (applies only to state=directory)
force:
required: false
default: "no"
choices: [ "yes", "no" ]
description:
- force the creation of the symlinks in two cases: the source file does
not exist (but will appear later); the destination exists and a file (so, we need to unlink the
"path" file and create symlink to the "src" file in place of it).
examples:
- code: "file: path=/etc/foo.conf owner=foo group=foo mode=0644"
description: Example from Ansible Playbooks
- code: "file: src=/file/to/link/to dest=/path/to/symlink owner=foo group=foo state=link"
- code: "action: file state=link path=/etc/localtime src=/usr/share/zoneinfo/Europe/Zurich force=yes"
description: Force /etc/locatime be the symbolic link to /usr/share/zoneinfo/Europe/Zurich
notes:
- See also M(copy), M(template), M(assemble)
requirements: [ ]
...
...
@@ -150,6 +164,7 @@ def main():
state
=
dict
(
choices
=
[
'file'
,
'directory'
,
'link'
,
'hard'
,
'absent'
],
default
=
'file'
),
path
=
dict
(
aliases
=
[
'dest'
,
'name'
],
required
=
True
),
recurse
=
dict
(
default
=
'no'
,
type
=
'bool'
),
force
=
dict
(
required
=
False
,
default
=
False
,
type
=
'bool'
),
diff_peek
=
dict
(
default
=
None
),
validate
=
dict
(
required
=
False
,
default
=
None
),
),
...
...
@@ -159,6 +174,7 @@ def main():
params
=
module
.
params
state
=
params
[
'state'
]
force
=
params
[
'force'
]
params
[
'path'
]
=
path
=
os
.
path
.
expanduser
(
params
[
'path'
])
# short-circuit for diff_peek
...
...
@@ -226,7 +242,10 @@ def main():
module
.
exit_json
(
path
=
path
,
changed
=
True
)
if
prev_state
!=
'absent'
and
prev_state
!=
state
:
module
.
fail_json
(
path
=
path
,
msg
=
'refusing to convert between
%
s and
%
s for
%
s'
%
(
prev_state
,
state
,
src
))
if
force
and
prev_state
==
'file'
and
state
==
'link'
:
pass
else
:
module
.
fail_json
(
path
=
path
,
msg
=
'refusing to convert between
%
s and
%
s for
%
s'
%
(
prev_state
,
state
,
src
))
if
prev_state
==
'absent'
and
state
==
'absent'
:
module
.
exit_json
(
path
=
path
,
changed
=
False
)
...
...
@@ -268,7 +287,8 @@ def main():
abs_src
=
src
else
:
module
.
fail_json
(
msg
=
"absolute paths are required"
)
if
not
os
.
path
.
exists
(
abs_src
):
if
not
os
.
path
.
exists
(
abs_src
)
and
not
force
:
module
.
fail_json
(
path
=
path
,
src
=
src
,
msg
=
'src file does not exist'
)
if
prev_state
==
'absent'
:
...
...
@@ -287,7 +307,14 @@ def main():
dolink
(
src
,
path
,
state
,
module
)
changed
=
True
elif
prev_state
==
'file'
:
module
.
fail_json
(
dest
=
path
,
src
=
src
,
msg
=
'Cannot link, file exists at destination'
)
if
not
force
:
module
.
fail_json
(
dest
=
path
,
src
=
src
,
msg
=
'Cannot link, file exists at destination'
)
else
:
if
module
.
check_mode
:
module
.
exit_json
(
changed
=
True
)
os
.
unlink
(
path
)
dolink
(
src
,
path
,
state
,
module
)
changed
=
True
else
:
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