mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 05:10:22 -07:00
Sets sane defaults for follow in file modules (#31430)
* Sets sane defaults for follow in file modules * Add a note in replace for removal of `follow` option
This commit is contained in:
parent
15b492ca57
commit
769881198f
3 changed files with 10 additions and 18 deletions
|
@ -77,16 +77,11 @@ options:
|
||||||
get the original file back if you somehow clobbered it incorrectly.
|
get the original file back if you somehow clobbered it incorrectly.
|
||||||
type: bool
|
type: bool
|
||||||
default: 'no'
|
default: 'no'
|
||||||
follow:
|
|
||||||
description:
|
|
||||||
- 'This flag indicates that filesystem links, if they exist, should be followed.'
|
|
||||||
type: bool
|
|
||||||
default: 'no'
|
|
||||||
version_added: "2.1"
|
|
||||||
notes:
|
notes:
|
||||||
- This module supports check mode.
|
- This module supports check mode.
|
||||||
- When using 'with_*' loops be aware that if you do not set a unique mark the block will be overwritten on each iteration.
|
- When using 'with_*' loops be aware that if you do not set a unique mark the block will be overwritten on each iteration.
|
||||||
- As of Ansible 2.3, the I(dest) option has been changed to I(path) as default, but I(dest) still works as well.
|
- As of Ansible 2.3, the I(dest) option has been changed to I(path) as default, but I(dest) still works as well.
|
||||||
|
- Option I(follow) has been removed in version 2.5, because this module modifies the contents of the file so I(follow=no) doesn't make sense.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
EXAMPLES = r"""
|
EXAMPLES = r"""
|
||||||
|
@ -203,8 +198,6 @@ def main():
|
||||||
|
|
||||||
params = module.params
|
params = module.params
|
||||||
path = params['path']
|
path = params['path']
|
||||||
if module.boolean(params.get('follow', None)):
|
|
||||||
path = os.path.realpath(path)
|
|
||||||
|
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
module.fail_json(rc=256,
|
module.fail_json(rc=256,
|
||||||
|
@ -315,7 +308,9 @@ def main():
|
||||||
if changed and not module.check_mode:
|
if changed and not module.check_mode:
|
||||||
if module.boolean(params['backup']) and path_exists:
|
if module.boolean(params['backup']) and path_exists:
|
||||||
module.backup_local(path)
|
module.backup_local(path)
|
||||||
write_changes(module, result, path)
|
# We should always follow symlinks so that we change the real file
|
||||||
|
real_path = os.path.realpath(params['path'])
|
||||||
|
write_changes(module, result, real_path)
|
||||||
|
|
||||||
if module.check_mode and not path_exists:
|
if module.check_mode and not path_exists:
|
||||||
module.exit_json(changed=changed, msg=msg, diff=diff)
|
module.exit_json(changed=changed, msg=msg, diff=diff)
|
||||||
|
|
|
@ -71,8 +71,9 @@ options:
|
||||||
follow:
|
follow:
|
||||||
description:
|
description:
|
||||||
- 'This flag indicates that filesystem links, if they exist, should be followed.'
|
- 'This flag indicates that filesystem links, if they exist, should be followed.'
|
||||||
|
- 'Previous to Ansible 2.5, this was C(no) by default.'
|
||||||
type: bool
|
type: bool
|
||||||
default: "no"
|
default: 'yes'
|
||||||
version_added: "1.8"
|
version_added: "1.8"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@ -176,6 +177,7 @@ def main():
|
||||||
original_basename=dict(required=False), # Internal use only, for recursive ops
|
original_basename=dict(required=False), # Internal use only, for recursive ops
|
||||||
recurse=dict(default=False, type='bool'),
|
recurse=dict(default=False, type='bool'),
|
||||||
force=dict(required=False, default=False, type='bool'),
|
force=dict(required=False, default=False, type='bool'),
|
||||||
|
follow=dict(required=False, default=True, type='bool'),
|
||||||
diff_peek=dict(default=None), # Internal use only, for internal checks in the action plugins
|
diff_peek=dict(default=None), # Internal use only, for internal checks in the action plugins
|
||||||
validate=dict(required=False, default=None), # Internal use only, for template and copy
|
validate=dict(required=False, default=None), # Internal use only, for template and copy
|
||||||
src=dict(required=False, default=None, type='path'),
|
src=dict(required=False, default=None, type='path'),
|
||||||
|
|
|
@ -78,12 +78,6 @@ options:
|
||||||
others:
|
others:
|
||||||
description:
|
description:
|
||||||
- All arguments accepted by the M(file) module also work here.
|
- All arguments accepted by the M(file) module also work here.
|
||||||
follow:
|
|
||||||
description:
|
|
||||||
- 'This flag indicates that filesystem links, if they exist, should be followed.'
|
|
||||||
type: bool
|
|
||||||
default: "no"
|
|
||||||
version_added: "1.9"
|
|
||||||
encoding:
|
encoding:
|
||||||
description:
|
description:
|
||||||
- "The character encoding for reading and writing the file."
|
- "The character encoding for reading and writing the file."
|
||||||
|
@ -91,6 +85,7 @@ options:
|
||||||
version_added: "2.4"
|
version_added: "2.4"
|
||||||
notes:
|
notes:
|
||||||
- As of Ansible 2.3, the I(dest) option has been changed to I(path) as default, but I(dest) still works as well.
|
- As of Ansible 2.3, the I(dest) option has been changed to I(path) as default, but I(dest) still works as well.
|
||||||
|
- Option I(follow) has been removed in version 2.5, because this module modifies the contents of the file so I(follow=no) doesn't make sense.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
EXAMPLES = r"""
|
EXAMPLES = r"""
|
||||||
|
@ -269,8 +264,8 @@ def main():
|
||||||
if changed and not module.check_mode:
|
if changed and not module.check_mode:
|
||||||
if params['backup'] and os.path.exists(path):
|
if params['backup'] and os.path.exists(path):
|
||||||
res_args['backup_file'] = module.backup_local(path)
|
res_args['backup_file'] = module.backup_local(path)
|
||||||
if params['follow'] and os.path.islink(path):
|
# We should always follow symlinks so that we change the real file
|
||||||
path = os.path.realpath(path)
|
path = os.path.realpath(path)
|
||||||
write_changes(module, to_bytes(result[0], encoding=encoding), path)
|
write_changes(module, to_bytes(result[0], encoding=encoding), path)
|
||||||
|
|
||||||
res_args['msg'], res_args['changed'] = check_file_attrs(module, changed, msg)
|
res_args['msg'], res_args['changed'] = check_file_attrs(module, changed, msg)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue