how can I set a variable then use it within a cmd.run execution

13 views
Skip to first unread message

Dennis Muller

unread,
May 20, 2025, 7:04:20 PMMay 20
to Salt-users
I am trying to set a variable for a site name, then use that variable within a cmd.run powershell command to test to see if it exists.

I cannot work out the jinja syntax though.


{% set site_url = "ftps-" ~ siteName ~ ".com" %}

{% set site_check = salt['cmd.run']('powershell -Command "(Get-Website | Where-Object { $_.Name -match \\"{{ site_url }}\" } ).Name"') %}

Dafydd Jones (techneg.it)

unread,
May 20, 2025, 8:53:14 PMMay 20
to salt-...@googlegroups.com
Common misunderstanding - you don't need to use the Jinja brackets {{ }} when you are already in a Jinja statement, just use the variable.
In this case you want to concatenate strings together using ~ to make the complete cmd.run argument. So something like:
'powershell -Command ".....' ~ site_url ~ '....."' but you'll need to take care with the quoting within the strings.

HTH,
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 visit https://groups.google.com/d/msgid/salt-users/f543d721-b445-460a-89e8-140f20bafe85n%40googlegroups.com.

Dennis Muller

unread,
May 20, 2025, 9:49:39 PMMay 20
to Salt-users
Great
Thank you

Reply all
Reply to author
Forward
0 new messages