0

I want to deploy the tool etckeeper via SaltStack.

Installating the RPM/DPKG is easy.

Next step is to call etckeeper init after the installation.

My current idea is this pseudo-code:

execute etckeeper init if /etc/.git does not exist

I read the docs for file.exists, but this does not help me.

How to solve this with SaltStack?

guettli
  • 3,113
  • 14
  • 59
  • 110

2 Answers2

4

You can use the "creates" argument to cmd.run, which tells saltstack to avoid running a command if a files already exists:

etckeeper_init:
  cmd.run:
    - name: etckeeper init
    - creates: /etc/.git
0

I found this solution. Other solutions are welcome!

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 %}
guettli
  • 3,113
  • 14
  • 59
  • 110