Error in execute script powershell in saltapi

9 views
Skip to first unread message

Antonio Remigio

unread,
Mar 29, 2023, 11:47:17 AM3/29/23
to Salt-users
Hi,

I'm search solution on group, but not finded!

I am utilizing
cherry_py of salt-api but i have error when i execute a script powershell by postman using JSON.

The following exemple:

{"client": "local",
    "username": "salt",
    "password": "salt",
    "eauth": "pam",
    "tgt": "ms-01",
    "fun": "cmd.run 'E:\\scripts\\rpo-promotion.ps1 xpto' shell='powershell' runas='sa...@domain.local' password='salt'"
}

Return:
{
    "return": [
        {
            "ms-01": "'cmd.run 'E:\\scripts\\rpo-promotion.ps1 xpto' shell='powershell' runas='sa...@domain.local' password='salt'' is not available."
        }
    ]
}

If i execute in fun: 'test.pin', return is success.

{"client": "local",
    "username": "salt",
    "password": "salt",
    "eauth": "pam",
    "tgt": "ms-01",
    "fun": "test.ping'"
}

Return:

{
    "return": [
        {
            "ms-01": true
        }
    ]
}

Salt-master = Centos 7
Salt-minion (ms-01) = Windows Server 2022 Standard

Somebody passed for this?

Thank's.

Simon Lundström

unread,
Mar 29, 2023, 12:08:17 PM3/29/23
to salt-...@googlegroups.com
Evening Antonio!

"fun" is the function to be called e.g. "cmd.run". The arguments to the
function must be sent via their own keys see e.g.
https://docs.saltproject.io/en/latest/ref/netapi/all/salt.netapi.rest_cherrypy.html#authentication

Since you're using shell=powershell e.g. that's a kwarg so that will be:
[...]
"fun": "cmd.run",
"kwarg": {
"shell": "powershell"
}
[...]

Note that the rpo-promotion is not a "kwarg" but a "arg" so you need to
put it there.

BR,
- Simon
> --
> 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<mailto:salt-users+...@googlegroups.com>.
> To view this discussion on the web visit https://groups.google.com/d/msgid/salt-users/08f1999e-1835-4edb-bf3b-1619df8a15f9n%40googlegroups.com<https://groups.google.com/d/msgid/salt-users/08f1999e-1835-4edb-bf3b-1619df8a15f9n%40googlegroups.com?utm_medium=email&utm_source=footer>.
Message has been deleted

Antonio Remigio

unread,
Mar 29, 2023, 2:30:36 PM3/29/23
to Salt-users
Thank you so much, @Simon!

It worked as you mentioned.

Sending exemplo:


{"client": "local",
    "username": "salt",
    "password": "salt",
    "eauth": "pam",
    "tgt": "ms-01",
    "fun": "cmd.run",
    "kwarg": {
        "shell": "powershell.exe",
        "runas": "salt",
        "password": "salt"
    },
    "arg": "E:\\scripts\\rpo-promotion.ps1 xpto"
}

PS: The user and password of session "kwarg" is of Windows where the minion is configured.

Thanks again.
Reply all
Reply to author
Forward
0 new messages