mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Check to see if a line is already commented before moving on
Fixes #37939
This commit is contained in:
parent
f2c045520d
commit
8a685b1820
1 changed files with 8 additions and 1 deletions
|
@ -3340,9 +3340,16 @@ def comment(name, regex, char='#', backup='.bak'):
|
|||
return _error(ret, check_msg)
|
||||
|
||||
unanchor_regex = regex.lstrip('^').rstrip('$')
|
||||
comment_regex = char + unanchor_regex
|
||||
|
||||
# Check if the line is already commented
|
||||
if __salt__['file.search'](name, comment_regex, multiline=True):
|
||||
commented = True
|
||||
else:
|
||||
commented = False
|
||||
|
||||
# Make sure the pattern appears in the file before continuing
|
||||
if not __salt__['file.search'](name, regex, multiline=True):
|
||||
if commented or not __salt__['file.search'](name, regex, multiline=True):
|
||||
if __salt__['file.search'](name, unanchor_regex, multiline=True):
|
||||
ret['comment'] = 'Pattern already commented'
|
||||
ret['result'] = True
|
||||
|
|
Loading…
Add table
Reference in a new issue