1

I use file.blockreplace like this:

etc_sudoers_{{ system_name }}:
  file.blockreplace:
    - name: /etc/sudoers
    - marker_start: "# START etc_sudoers_{{ system_name }} -DO-NOT-EDIT-"
    - marker_end: "# END etc_sudoers_{{ system_name }} --"
    - content: |
        {{system_name}} ALL = NOPASSWD: /bin/systemctl restart apache2*
    - append_if_not_found: True
    - show_changes: True

This creates an entry in the file like this:

# START etc_sudoers_foo_c123_dpci01051321 -DO-NOT-EDIT-
foo_c123_dpci01051321 ALL = NOPASSWD: /bin/systemctl restart apache2*
# END etc_sudoers_foo_c123_dpci01051321 --

Now I want to remove the whole block (inclusive the START/END markers). How to do this with saltstack?

guettli
  • 3,113
  • 14
  • 59
  • 110

1 Answers1

1

I found this solution. Better ones are more than welcome :-)

remove_django__etc_sudoers_{{ system_name }}:
  file.replace:
    - name: /etc/sudoers
    - pattern: "# START etc_sudoers_{{ system_name }} -DO-NOT-EDIT-.*?# END etc_sudoers_{{ system_name }} --"
    - flags: ['MULTILINE', 'DOTALL']
    - repl: ''
    - ignore_if_missing: True
guettli
  • 3,113
  • 14
  • 59
  • 110