Saltstack
SaltStack:如何刪除使用 file.blockreplace 創建的塊?
我像這樣使用file.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 --
現在我想刪除整個塊(包括開始/結束標記)。如何用鹽堆做到這一點?
我找到了這個解決方案。更好的更受歡迎:-)
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