Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check if there attributes to set #78707

Merged
merged 1 commit into from Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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
Expand Up @@ -958,7 +958,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
Expand Up @@ -1418,3 +1418,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