mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Adding "follow" param for file/copy options
Also modifies the template action plugin to use this new param when executing the file/copy modules for templating so that links are preserved correctly. Fixes #8998
This commit is contained in:
parent
79a2e586fe
commit
b376e208c7
7 changed files with 96 additions and 13 deletions
|
@ -207,3 +207,33 @@
|
|||
- name: clean up
|
||||
file: dest=/tmp/worldwritable state=absent
|
||||
|
||||
# test overwritting a link using "follow=yes" so that the link
|
||||
# is preserved and the link target is updated
|
||||
|
||||
- name: create a test file to symlink to
|
||||
copy: dest={{output_dir}}/follow_test content="this is the follow test file\n"
|
||||
|
||||
- name: create a symlink to the test file
|
||||
file: path={{output_dir}}/follow_link src='./follow_test' state=link
|
||||
|
||||
- name: update the test file using follow=True to preserve the link
|
||||
copy: dest={{output_dir}}/follow_link content="this is the new content\n" follow=yes
|
||||
register: replace_follow_result
|
||||
|
||||
- name: stat the link path
|
||||
stat: path={{output_dir}}/follow_link
|
||||
register: stat_link_result
|
||||
|
||||
- name: assert that the link is still a link
|
||||
assert:
|
||||
that:
|
||||
- stat_link_result.stat.islnk
|
||||
|
||||
- name: get the md5 of the link target
|
||||
shell: md5sum {{output_dir}}/follow_test | cut -f1 -sd ' '
|
||||
register: target_file_result
|
||||
|
||||
- name: assert that the link target was updated
|
||||
assert:
|
||||
that:
|
||||
- replace_follow_result.md5sum == target_file_result.stdout
|
||||
|
|
|
@ -405,3 +405,29 @@
|
|||
that:
|
||||
- result.mode == '0444'
|
||||
|
||||
# test the file module using follow=yes, so that the target of a
|
||||
# symlink is modified, rather than the link itself
|
||||
|
||||
- name: create a test file
|
||||
copy: dest={{output_dir}}/test_follow content="this is a test file\n" mode=0666
|
||||
|
||||
- name: create a symlink to the test file
|
||||
file: path={{output_dir}}/test_follow_link src="./test_follow" state=link
|
||||
|
||||
- name: modify the permissions on the link using follow=yes
|
||||
file: path={{output_dir}}/test_follow_link mode=0644 follow=yes
|
||||
register: result
|
||||
|
||||
- name: assert that the chmod worked
|
||||
assert:
|
||||
that:
|
||||
- result.changed
|
||||
|
||||
- name: stat the link target
|
||||
stat: path={{output_dir}}/test_follow
|
||||
register: result
|
||||
|
||||
- name: assert that the link target was modified correctly
|
||||
assert:
|
||||
that:
|
||||
- result.stat.mode == '0644'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue