Skip to content

Commit

Permalink
Show diff when file: state=link changes the symlink target (ansible#2…
Browse files Browse the repository at this point in the history
…2243)

* Show diff when file: state=link changes the symlink target

* Integration test for symlink target change

* Also check soft link idempotency
  • Loading branch information
mgedmin authored and bcoca committed Mar 6, 2017
1 parent 228131d commit 15c7288
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/ansible/modules/files/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ def main():
elif prev_state == 'link':
b_old_src = os.readlink(b_path)
if b_old_src != b_src:
diff['before']['src'] = to_native(b_old_src, errors='strict')
diff['after']['src'] = src
changed = True
elif prev_state == 'hard':
if not (state == 'hard' and os.stat(b_path).st_ino == os.stat(b_src).st_ino):
Expand Down
20 changes: 20 additions & 0 deletions test/integration/targets/file/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,26 @@
that:
- "file5_result.changed == true"

- name: change soft link to relative
file: src={{output_file|basename}} dest={{output_dir}}/soft.txt state=link
register: file5a_result

- name: verify that the file was marked as changed
assert:
that:
- "file5a_result.changed == true"
- "file5a_result.diff.before.src == output_file|expanduser"
- "file5a_result.diff.after.src == output_file|basename"

- name: soft link idempotency check
file: src={{output_file|basename}} dest={{output_dir}}/soft.txt state=link
register: file5b_result

- name: verify that the file was not marked as changed
assert:
that:
- "file5b_result.changed == false"

- name: create hard link to file
file: src={{output_file}} dest={{output_dir}}/hard.txt state=hard
register: file6_result
Expand Down

0 comments on commit 15c7288

Please sign in to comment.