![SaltStack:如果 /etc/.git 不存在,则执行“etckeeper init”](https://linux22.com/image/718530/SaltStack%EF%BC%9A%E5%A6%82%E6%9E%9C%20%2Fetc%2F.git%20%E4%B8%8D%E5%AD%98%E5%9C%A8%EF%BC%8C%E5%88%99%E6%89%A7%E8%A1%8C%E2%80%9Cetckeeper%20init%E2%80%9D.png)
答案1
您可以使用 cmd.run 的“creates”参数,它告诉 saltstack 如果文件已存在则避免运行命令:
etckeeper_init:
cmd.run:
- name: etckeeper init
- creates: /etc/.git
答案2
我找到了这个解决方案。欢迎提供其他解决方案!
etckeeper:
pkg.installed
{%- if not salt['file.directory_exists' ]('/etc/.git') %}
init_etckeeper:
cmd.run:
- name: etckeeper init
initial_commit_etckeeper:
cmd.run:
- name: etckeeper commit -m "initial commit"
{%- endif %}