string contains

37 views
Skip to first unread message

brad.v...@gmail.com

unread,
Feb 21, 2024, 6:40:31 AMFeb 21
to Salt-users
I have a salt state to copy a log file from the minions up to the master.  On each salt master, I'm trying to create a jinja statement to create the deposit directory, but not having luck.  How do I check if grains['host'] contains 'salt?'

{% if grains['host'].contains 'salt' %}

mk-deposit:
  file.directory:
    - name: /var/cache/salt/master/minions/verify
    - user: root
    - group: root
    - dir_mode: 755

{% endif %}

cp-post-verification:
  module.run:
    - name: cp.push
    - path: /root/kickstart-logs/{{ grains['host'] }}-verify.log
    - upload_path: /var/cache/salt/master/minions/verify

How to I write if grains['host'] contains the string 'salt' ?

Dafydd Jones (techneg.it)

unread,
Feb 21, 2024, 12:26:22 PMFeb 21
to salt-...@googlegroups.com
Try {% if "salt" in grains["host"] %}

Dafydd

--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/salt-users/71a52640-270e-44ac-8865-dcc6f2bfdcddn%40googlegroups.com.

Brad Van Orden

unread,
Feb 21, 2024, 12:38:36 PMFeb 21
to salt-...@googlegroups.com
Great!  Thanks!

You received this message because you are subscribed to a topic in the Google Groups "Salt-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/salt-users/2P_oTZT8nPg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to salt-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/salt-users/CA%2BMg1C1%2BFSejQ%2BTL1N%3DG7RqpZgg4wbAnB0NFiSWjuG4Z68jEOA%40mail.gmail.com.

Phipps, Thomas

unread,
Feb 21, 2024, 12:40:47 PMFeb 21
to salt-...@googlegroups.com

there is also {% if salt["match.grains"]("host:*salt*") %}


--
Reply all
Reply to author
Forward
0 new messages