|
|
@ -81,8 +81,8 @@ options:
|
|
|
|
default: null
|
|
|
|
default: null
|
|
|
|
choices: []
|
|
|
|
choices: []
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- path of the file to link to (applies only to C(state=link)). Will accept absolute,
|
|
|
|
- path of the file to link to (applies only to C(state= link or hard)). Will accept absolute,
|
|
|
|
relative and nonexisting paths. Relative paths are not expanded.
|
|
|
|
relative and nonexisting (with C(force)) paths. Relative paths are not expanded.
|
|
|
|
seuser:
|
|
|
|
seuser:
|
|
|
|
required: false
|
|
|
|
required: false
|
|
|
|
default: null
|
|
|
|
default: null
|
|
|
@ -266,8 +266,12 @@ def main():
|
|
|
|
|
|
|
|
|
|
|
|
elif state in ['link','hard']:
|
|
|
|
elif state in ['link','hard']:
|
|
|
|
|
|
|
|
|
|
|
|
if not os.path.exists(src) and not force:
|
|
|
|
absrc = src
|
|
|
|
module.fail_json(path=path, src=src, msg='src file does not exist')
|
|
|
|
if not os.path.isabs(absrc):
|
|
|
|
|
|
|
|
absrc = os.path.normpath('%s/%s' % (os.path.dirname(path), absrc))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not os.path.exists(absrc) and not force:
|
|
|
|
|
|
|
|
module.fail_json(path=path, src=src, msg='src file does not exist, use "force=yes" if you really want to create the link: %s' % absrc)
|
|
|
|
|
|
|
|
|
|
|
|
if state == 'hard':
|
|
|
|
if state == 'hard':
|
|
|
|
if not os.path.isabs(src):
|
|
|
|
if not os.path.isabs(src):
|
|
|
@ -297,7 +301,7 @@ def main():
|
|
|
|
if changed and not module.check_mode:
|
|
|
|
if changed and not module.check_mode:
|
|
|
|
if prev_state != 'absent':
|
|
|
|
if prev_state != 'absent':
|
|
|
|
# try to replace atomically
|
|
|
|
# try to replace atomically
|
|
|
|
tmppath = ".%s.%s.%s.tmp" % (path,os.getpid(),time.time())
|
|
|
|
tmppath = '/'.join([os.path.dirname(path), ".%s.%s.tmp" % (os.getpid(),time.time())])
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
if state == 'hard':
|
|
|
|
if state == 'hard':
|
|
|
|
os.link(src,tmppath)
|
|
|
|
os.link(src,tmppath)
|
|
|
@ -307,13 +311,14 @@ def main():
|
|
|
|
except OSError, e:
|
|
|
|
except OSError, e:
|
|
|
|
os.unlink(tmppath)
|
|
|
|
os.unlink(tmppath)
|
|
|
|
module.fail_json(path=path, msg='Error while replacing: %s' % str(e))
|
|
|
|
module.fail_json(path=path, msg='Error while replacing: %s' % str(e))
|
|
|
|
try:
|
|
|
|
else:
|
|
|
|
if state == 'hard':
|
|
|
|
try:
|
|
|
|
os.link(src,path)
|
|
|
|
if state == 'hard':
|
|
|
|
else:
|
|
|
|
os.link(src,path)
|
|
|
|
os.symlink(src, path)
|
|
|
|
else:
|
|
|
|
except OSError, e:
|
|
|
|
os.symlink(src, path)
|
|
|
|
module.fail_json(path=path, msg='Error while linking: %s' % str(e))
|
|
|
|
except OSError, e:
|
|
|
|
|
|
|
|
module.fail_json(path=path, msg='Error while linking: %s' % str(e))
|
|
|
|
|
|
|
|
|
|
|
|
changed = module.set_fs_attributes_if_different(file_args, changed)
|
|
|
|
changed = module.set_fs_attributes_if_different(file_args, changed)
|
|
|
|
module.exit_json(dest=path, src=src, changed=changed)
|
|
|
|
module.exit_json(dest=path, src=src, changed=changed)
|
|
|
|