[uyuni-users] grain item match
Hi, at Salt's top.sls an expression like the following one is running fine: base: 'osfinger:SLES-15': - match: - common.ad.ad-sles15 meaning that only on a minion running SLES-15 the SLS common/ad/ad-sles15.sls will get executed. Trying to implement something similar using Uyuni's WebUI in order to create a "Configuration file" (SLS) doesn't work: ServerSpecial: 'host:server01': - match: grain - file.managed: - name: .... (I leave out the rest as it doesn't cause the trouble) My intention is that "file managing" only happens if the hostname is "server01". During deployment the logfile minion says: "State 'host:server01.__call__' was not found in SLS 'manager_org_1.SLES15-WF-SrvSpez-SLS' Reason: 'host:server01.__call__' is not available. I have the vague idea that this happens because this grain-item-matching is only allowed at top.sls but as there is no access to top.sls using Uyuni's WebUI I wonder how this could be done with the WebUI? Any idea? -- Gruss, Tobias Crefeld. xmpp (no email): crefeld@xabber.de -- To unsubscribe, e-mail: uyuni-users+unsubscribe@opensuse.org To contact the owner, e-mail: uyuni-users+owner@opensuse.org
Hello Tobias, Am 20.05.20 um 19:37 schrieb Tobias Crefeld:
I have the vague idea that this happens because this grain-item-matching is only allowed at top.sls but as there is no access to top.sls using Uyuni's WebUI I wonder how this could be done with the WebUI?
you are right, matching in the way you are using it will only work in top.sls You can use jinja within states to achieve that: {% if salt.grains.get('host') == 'server01' %} ...your state data... {% endif %} Cheers Stefan -- Stefan Bogner Linux / Unix Consultant & Trainer Tel: +491608463534 Mail: bogner@b1-systems.de B1 Systems GmbH Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537
Am Fri, 22 May 2020 08:01:27 +0200
schrieb Stefan Bogner
You can use jinja within states to achieve that:
{% if salt.grains.get('host') == 'server01' %}
...your state data...
{% endif %}
Thanks for your idea! As yet I haven't had a look at jinja but as this approach came close to what I was looking for I gave it a try. With some examples from the web finally I found this solution that works fine now:
access.conf: file.managed: - name: /etc/security/access.conf {% if salt.grains.get('host') == 'server01' %} - source: salt://manager_org_1/SLES15-WF-SrvSpez-SLS/etc/security/access.conf-prodvvvo {% elif salt.grains.get('host') == 'server02' %} - source: salt://manager_org_1/SLES15-WF-SrvSpez-SLS/etc/security/access.conf-prodwebservice {% else %} - source: salt://manager_org_1/SLES15-WF-SrvSpez-SLS/etc/security/access.conf-testserver {% endif %} - user: root - group: root - mode: '0644'
(BTW: the source files were created as configuration-(text-)files within the same configuration channel) -- Gruss, Tobias Crefeld. xmpp (no email): crefeld@xabber.de -- To unsubscribe, e-mail: uyuni-users+unsubscribe@opensuse.org To contact the owner, e-mail: uyuni-users+owner@opensuse.org
On 22/05/20 16:50:47, Tobias Crefeld wrote:
access.conf: file.managed: - name: /etc/security/access.conf {% if salt.grains.get('host') == 'server01' %} - source: salt://manager_org_1/SLES15-WF-SrvSpez-SLS/etc/security/access.conf-prodvvvo {% elif salt.grains.get('host') == 'server02' %} - source: salt://manager_org_1/SLES15-WF-SrvSpez-SLS/etc/security/access.conf-prodwebservice {% else %} - source: salt://manager_org_1/SLES15-WF-SrvSpez-SLS/etc/security/access.conf-testserver {% endif %} - user: root - group: root - mode: '0644'
(BTW: the source files were created as configuration-(text-)files within the same configuration channel)
A little bit more concise, easier to read and DRY (Don't repeat yourself): <snip> {% if salt.grains.get('host') == 'server01' %} {% set suffix='prodvvvo' %} {% elif salt.grains.get('host') == 'server02' %} {% set suffix='prodwebservice' %} {% else %} {% set suffix='testserver' %} access.conf: file.managed: - name: /etc/security/access.conf - source: salt://manager_org_1/SLES15-WF-SrvSpez-SLS/etc/security/access.conf-{{ suffix }} - user: root - group: root - mode: '0644' </snip> But this looks like a use case for a proper template, so you should read up on https://docs.saltstack.com/en/master/topics/tutorials/states_pt3.html and https://docs.saltstack.com/en/latest/topics/jinja/index.html Regards, Mattias
participants (3)
-
Mattias Giese
-
Stefan Bogner
-
Tobias Crefeld