saltstack / saltstack/salt

[BUG] cmd.run onlyif powershell

Open
#63,820 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug expected-behavior needs-triage
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

Description
Can't get cmd.run working with onlyif and powershell.
As you can see in the screenshot, the exact same command is executed and returns a False, so it shouldn't have been executed in the first place.
I tried also with " instead of ' and completely without and adding powershell infront. But either it's always True or always False independent of the real status.
And it's also really hard to find examples for Windows at all.

Expected behavior
command should only be executed if onlyif is true.

Screenshots
image

Versions Report
Salt Version:
Salt: 3005.1

Dependency Versions:
cffi: Not Installed
cherrypy: unknown
dateutil: 2.7.3
docker-py: Not Installed
gitdb: 2.0.6
gitpython: 3.0.7
Jinja2: 2.10.1
libgit2: Not Installed
M2Crypto: Not Installed
Mako: Not Installed
msgpack: 0.6.2
msgpack-pure: Not Installed
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pycryptodome: 3.6.1
pygit2: Not Installed
Python: 3.8.10 (default, Nov 14 2022, 12:59:47)
python-gnupg: 0.4.5
PyYAML: 5.3.1
PyZMQ: 20.0.0
smmap: 2.0.5
timelib: Not Installed
Tornado: 4.5.3
ZMQ: 4.3.2

System Versions:
dist: ubuntu 20.04 focal
locale: utf-8
machine: x86_64
release: 5.4.0-144-generic
system: Linux
version: Ubuntu 20.04 focal

  DisableDefenderRTP:
    cmd.run:
      - name: '(Get-MpComputerStatus).RealTimeProtectionEnabled'
      - shell: powershell
      - onlyif: '(Get-MpComputerStatus).RealTimeProtectionEnabled'

Additional context
Add any other context about the problem here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Salt's cmd.run entry point and the onlyif handling for the powershell shell, using the provided YAML example and Salt 3005.1 environment to reproduce the behavior. Trace how the condition is evaluated versus the command and verify that the command runs only when the PowerShell condition returns true.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell, python
Domain
infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.