Salt on Windows - run a script after package install

186 views
Skip to first unread message

Ed Killian

unread,
Jun 19, 2019, 8:39:07 PM6/19/19
to Salt-users
Is there a way to run a bat script after a package install?

Christian McHugh

unread,
Jun 20, 2019, 2:48:08 AM6/20/19
to Salt-users
If your package install returns a change notice to salt, then you can use the onchanges requisite, see https://docs.saltstack.com/en/latest/ref/states/requisites.html#onchanges

The state would look something like:

winlogbeat:
  pkg.installed:
    - pkgs:
      - winlogbeat
postbeat:
  cmd.source:
    - source: salt://winlogbeat/files/post_install.bat
    - onchanges:
      - pkg: winlogbeat

Ed Killian

unread,
Jun 20, 2019, 3:01:36 PM6/20/19
to Salt-users
That doesn't seem to work, at least the way I'm trying to use it. Here's the code I'm trying to use now:

{% if 'Windows' in grains['os']  %}
{% set PROGRAM_FILES = "%ProgramFiles%" %}
nessus-agent:
  pkg.installed:
    - order: 1000

link.bat:
  cmd.run:
    - unless: \"C:\Program Files\Tenable\Nessus\nessuscli\" agent status | grep Linked
    - source: salt://win/repo-ng/nessus_agent/link.bat
    - order: 1002

{% endif %}

But I get an error:

----------
          ID: link.bat
    Function: cmd.run
      Result: False
     Comment: Command "link.bat" run
     Started: 14:58:57.624216
    Duration: 109.2 ms
     Changes:  
              ----------
              pid:
                  4612
              retcode:
                  1
              stderr:
                  'link.bat' is not recognized as an internal or external command,
                  operable program or batch file.
              stdout:

Dafydd Jones (techneg.it)

unread,
Jun 20, 2019, 7:04:05 PM6/20/19
to salt-...@googlegroups.com
There's a bit of a mixup here. If you’re running a script use cmd.script; otherwise you use cmd.run. Check the docs.

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/313f52ae-117b-45d4-a57e-7c5f5bf07d8e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ed Killian

unread,
Jun 21, 2019, 9:29:22 PM6/21/19
to Salt-users
Thanks! That's what I needed.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages