mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-23 10:51:24 -07:00
accept + and - modifiers for file attributes (#40061)
* accept + and - modifiers for file attributes * tests for adding/removing file attributes
This commit is contained in:
parent
8ab0d654f3
commit
75e9b76c15
2 changed files with 27 additions and 6 deletions
|
@ -1355,10 +1355,15 @@ class AnsibleModule(object):
|
|||
|
||||
existing = self.get_file_attributes(b_path)
|
||||
|
||||
if existing.get('attr_flags', '') != attributes:
|
||||
attr_mod = '='
|
||||
if attributes.startswith(('-', '+')):
|
||||
attr_mod = attributes[0]
|
||||
attributes = attributes[1:]
|
||||
|
||||
if existing.get('attr_flags', '') != attributes or attr_mod == '-':
|
||||
attrcmd = self.get_bin_path('chattr')
|
||||
if attrcmd:
|
||||
attrcmd = [attrcmd, '=%s' % attributes, b_path]
|
||||
attrcmd = [attrcmd, '%s%s' % (attr_mod, attributes), b_path]
|
||||
changed = True
|
||||
|
||||
if diff is not None:
|
||||
|
@ -1367,7 +1372,7 @@ class AnsibleModule(object):
|
|||
diff['before']['attributes'] = existing.get('attr_flags')
|
||||
if 'after' not in diff:
|
||||
diff['after'] = {}
|
||||
diff['after']['attributes'] = attributes
|
||||
diff['after']['attributes'] = '%s%s' % (attr_mod, attributes)
|
||||
|
||||
if not self.check_mode:
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue