我用文件.blockreplace像这样:
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
这会在文件中创建一个如下条目:
# START etc_sudoers_foo_c123_dpci01051321 -DO-NOT-EDIT-
foo_c123_dpci01051321 ALL = NOPASSWD: /bin/systemctl restart apache2*
# END etc_sudoers_foo_c123_dpci01051321 --
现在我想删除整个块(包括 START/END 标记)。如何使用 saltstack 执行此操作?
答案1
我找到了这个解决方案。欢迎提供更好的解决方案 :-)
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