I use file.blockreplace like this:

etc_sudoers_{{ system_name }}:
    - 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?


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

remove_django__etc_sudoers_{{ system_name }}:
    - 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.