matze502
matze502

Reputation: 48

Salt state with check if file on salt master exists

I try to create the following state, but I don't know how to write the if clause? Maybe someone can help me with it. What I try to accomplish is that salt takes a configuration file if a file with the target hostname exists and else take the default config.

example:

{% if ??? test -f ??? salt://ntpd/ntp.conf_{{ salt['grains.get']('host') }} %}
ntpd-config:
  file.managed:
    - name: /etc/ntp.conf
    - source: salt://ntpd/ntp.conf_{{ salt['grains.get']('host') }}
    - user: root
    - group: root
    - file_mode: 644
    - require:
      - ntpd-pkgs
{% else %}
ntpd-config:
  file.managed:
    - name: /etc/ntp.conf
    - source: salt://ntpd/ntp.conf
    - user: root
    - group: root
    - file_mode: 644
    - require:
      - ntpd-pkgs
{% endif %}

Hope, someone could help me.

Thanks in advance!

Matthias

Upvotes: 1

Views: 1188

Answers (1)

matze502
matze502

Reputation: 48

I just found the answer by myself.

Found out in the documentation that I can define multiple sources. The last one is then the default one if none of the others bevore exists.

This now works:

ntpd-config:
  file.managed:
    - name: /etc/ntp.conf
    - source:
        - salt://ntpd/ntp.conf_{{ salt['grains.get']('host') }}
        - salt://ntpd/ntp.conf

Upvotes: 1

Related Questions