Running a script directly from the master on the minion

2,769 views
Skip to first unread message

Stephen Wood

unread,
Oct 5, 2013, 6:53:57 PM10/5/13
to salt-...@googlegroups.com
Is there a way to run a script from the master on a minion as part of the sls file?

Right now the SLS looks like this:

/usr/local/sbin/my_script:
  file:
    - managed
    - mode: 700
    - source: salt://scripts/my_script

bash /usr/local/sbin/my_script:
  cmd.run:
    - require:
      - file: /usr/local/sbin/my_script

Also note I had to append "bash" to run the ID for the script, or else I get warnings for duplicate IDs. Is there a better way to accomplish this type of thing?
--

Shawn Milochik

unread,
Oct 5, 2013, 8:21:21 PM10/5/13
to salt-...@googlegroups.com
You can do this:

    Replace "/usr/local/sbin/my_script" with "my_script" and add a "- name" parameter of: "/usr/local/sbin/my_script"
  Replace "bash /usr/local/sbin/my_script" with "run_my_script" and add the script name as the "- name" parameter.

I don't understand the first part of your question; this should definitely copy the script to the minion and execute it there.


Stephen Wood

unread,
Oct 5, 2013, 9:21:24 PM10/5/13
to salt-...@googlegroups.com, Sh...@milochik.com
Sorry I wasn't more clear. I thought there would be a way to collapse the two commands into a single one. Instead of downloading it first to the host, and then execute it. I don't want to file to actually exist on the minion after execution. Any ideas?

Thanks for the tip on giving it a name. That greatly helps with ID conflicts!

Avi Marcus

unread,
Oct 5, 2013, 11:59:50 PM10/5/13
to salt-...@googlegroups.com

I think cmd.run allows a source arg. You'll have to check the docs.

-Avi

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Zogg

unread,
Oct 6, 2013, 6:35:47 AM10/6/13
to salt-...@googlegroups.com
Just remove it after execution with 'file.absent' state. :)
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
Message has been deleted

Colton Myers

unread,
Oct 6, 2013, 1:02:51 PM10/6/13
to salt-...@googlegroups.com
I think what you're looking for is the `cmd.script` state:  http://docs.saltstack.com/ref/states/all/salt.states.cmd.html#salt.states.cmd.script

--
Colton Myers


--
Reply all
Reply to author
Forward
0 new messages