check if there attributes to set (#78707)

Fixes: #76727
pull/82383/head
Danny Luwel 5 months ago committed by GitHub
parent dd0138ba21
commit 9b002d2e63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- check if there are attributes to set before attempting to set them (https://github.com/ansible/ansible/issues/76727)

@ -958,7 +958,7 @@ class AnsibleModule(object):
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]

@ -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

Loading…
Cancel
Save