答案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 %}