|
|
|
@ -16,6 +16,10 @@
|
|
|
|
|
mode: 0444
|
|
|
|
|
register: copy_result
|
|
|
|
|
|
|
|
|
|
- name: Record the sha of the test file for later tests
|
|
|
|
|
set_fact:
|
|
|
|
|
remote_file_hash: "{{ copy_result['checksum'] }}"
|
|
|
|
|
|
|
|
|
|
- name: Check the mode of the output file
|
|
|
|
|
file:
|
|
|
|
|
name: "{{ remote_file }}"
|
|
|
|
@ -173,7 +177,7 @@
|
|
|
|
|
- name: Create a hardlink to the file
|
|
|
|
|
file:
|
|
|
|
|
src: '{{ remote_file }}'
|
|
|
|
|
dest: '{{ output_dir }}/hard.lnk'
|
|
|
|
|
dest: '{{ remote_dir }}/hard.lnk'
|
|
|
|
|
state: hard
|
|
|
|
|
|
|
|
|
|
- name: copy the same contents into place
|
|
|
|
@ -191,7 +195,7 @@
|
|
|
|
|
|
|
|
|
|
- name: Check the stat results of the hard link
|
|
|
|
|
stat:
|
|
|
|
|
path: "{{ output_dir }}/hard.lnk"
|
|
|
|
|
path: "{{ remote_dir }}/hard.lnk"
|
|
|
|
|
register: hlink_results
|
|
|
|
|
|
|
|
|
|
- name: Check that the file did not change
|
|
|
|
@ -216,7 +220,7 @@
|
|
|
|
|
|
|
|
|
|
- name: Check the stat results of the hard link
|
|
|
|
|
stat:
|
|
|
|
|
path: "{{ output_dir }}/hard.lnk"
|
|
|
|
|
path: "{{ remote_dir }}/hard.lnk"
|
|
|
|
|
register: hlink_results
|
|
|
|
|
|
|
|
|
|
- name: Check that the file changed permissions but is still the same
|
|
|
|
@ -242,7 +246,7 @@
|
|
|
|
|
|
|
|
|
|
- name: Check the stat results of the hard link
|
|
|
|
|
stat:
|
|
|
|
|
path: "{{ output_dir }}/hard.lnk"
|
|
|
|
|
path: "{{ remote_dir }}/hard.lnk"
|
|
|
|
|
register: hlink_results
|
|
|
|
|
|
|
|
|
|
- name: Check that the file changed and hardlink was broken
|
|
|
|
@ -1105,6 +1109,10 @@
|
|
|
|
|
|
|
|
|
|
remote_user: root
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Follow=True tests
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
# test overwriting a link using "follow=yes" so that the link
|
|
|
|
|
# is preserved and the link target is updated
|
|
|
|
|
|
|
|
|
@ -1122,7 +1130,7 @@
|
|
|
|
|
- name: Update the test file using follow=True to preserve the link
|
|
|
|
|
copy:
|
|
|
|
|
dest: "{{ remote_dir }}/follow_link"
|
|
|
|
|
content: "this is the new content\n"
|
|
|
|
|
src: foo.txt
|
|
|
|
|
follow: yes
|
|
|
|
|
register: replace_follow_result
|
|
|
|
|
|
|
|
|
@ -1131,19 +1139,37 @@
|
|
|
|
|
path: "{{ remote_dir }}/follow_link"
|
|
|
|
|
register: stat_link_result
|
|
|
|
|
|
|
|
|
|
- name: Assert that the link is still a link
|
|
|
|
|
- name: Assert that the link is still a link and contents were changed
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- stat_link_result.stat.islnk
|
|
|
|
|
- stat_link_result['stat']['islnk']
|
|
|
|
|
- stat_link_result['stat']['lnk_target'] == './follow_test'
|
|
|
|
|
- replace_follow_result['changed']
|
|
|
|
|
- "replace_follow_result['checksum'] == remote_file_hash"
|
|
|
|
|
|
|
|
|
|
- name: Get the checksum of the link target
|
|
|
|
|
shell: "{{ ansible_python_interpreter }} -c 'import hashlib; print(hashlib.sha1(open(\"{{remote_dir | expanduser}}/follow_test\", \"rb\").read()).hexdigest())'"
|
|
|
|
|
register: target_file_result
|
|
|
|
|
# Symlink handling when the dest is already there
|
|
|
|
|
# https://github.com/ansible/ansible-modules-core/issues/1568
|
|
|
|
|
|
|
|
|
|
- name: test idempotency by trying to copy to the symlink with the same contents
|
|
|
|
|
copy:
|
|
|
|
|
dest: "{{ remote_dir }}/follow_link"
|
|
|
|
|
src: foo.txt
|
|
|
|
|
follow: yes
|
|
|
|
|
register: replace_follow_result
|
|
|
|
|
|
|
|
|
|
- name: Assert that the link target was updated
|
|
|
|
|
- name: Stat the link path
|
|
|
|
|
stat:
|
|
|
|
|
path: "{{ remote_dir }}/follow_link"
|
|
|
|
|
register: stat_link_result
|
|
|
|
|
|
|
|
|
|
- name: Assert that the link is still a link and contents were changed
|
|
|
|
|
assert:
|
|
|
|
|
that:
|
|
|
|
|
- replace_follow_result.checksum == target_file_result.stdout
|
|
|
|
|
- stat_link_result['stat']['islnk']
|
|
|
|
|
- stat_link_result['stat']['lnk_target'] == './follow_test'
|
|
|
|
|
- not replace_follow_result['changed']
|
|
|
|
|
- replace_follow_result['checksum'] == remote_file_hash
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: Update the test file using follow=False to overwrite the link
|
|
|
|
|
copy:
|
|
|
|
@ -1169,6 +1195,13 @@
|
|
|
|
|
- "stat_results.stat.checksum == ('modified'|hash('sha1'))"
|
|
|
|
|
- "not stat_results.stat.islnk"
|
|
|
|
|
|
|
|
|
|
# test overwriting a link using "follow=yes" so that the link
|
|
|
|
|
# is preserved and the link target is updated when the thing being copied is a link
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# File mode tests
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
- name: setup directory for test
|
|
|
|
|
file: state=directory dest={{remote_dir }}/directory mode=0755
|
|
|
|
|
|
|
|
|
|