Skip to content

Commit

Permalink
Add fix for issue 76727: check if there attributes to set before atte…
Browse files Browse the repository at this point in the history
…mpting to set them
  • Loading branch information
pc-explore committed Sep 4, 2022
1 parent 3b9f187 commit ef6d3e5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- check if there are attributes to set before attempting to set them (https://github.com/ansible/ansible/issues/76727)
2 changes: 1 addition & 1 deletion lib/ansible/module_utils/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ def set_attributes_if_different(self, path, attributes, changed, diff=None, expa
attr_mod = attributes[0]
attributes = attributes[1:]

if existing.get('attr_flags', '') != attributes or attr_mod == '-':
if attributes and (existing.get('attr_flags', '') != attributes or attr_mod == '-'):
attrcmd = self.get_bin_path('chattr')
if attrcmd:
attrcmd = [attrcmd, '%s%s' % (attr_mod, attributes), b_path]
Expand Down
27 changes: 27 additions & 0 deletions test/integration/targets/lineinfile/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1397,3 +1397,30 @@
- testend1 is changed
- testend2 is changed
- testend_file.stat.checksum == 'ef36116966836ce04f6b249fd1837706acae4e19'

- name: Integration test for issue 76727
block:
- name: Create a symbolic link for the test file
file:
src: "{{ remote_tmp_dir }}/test.txt"
dest: "{{ remote_tmp_dir }}/test-76727.txt"
state: link

- name: Insert a line and back it up
lineinfile:
dest: "{{ remote_tmp_dir }}/test-76727.txt"
state: present
line: "#Line for issue 76727"
backup: yes
register: result1

- name: Stat the backup file
stat:
path: "{{ result1.backup }}"
register: result2

- name: Assert that the line was inserted and backup is created
assert:
that:
- result1 is changed
- result2.stat.exists

0 comments on commit ef6d3e5

Please sign in to comment.