Interactive cmd.run

944 views
Skip to first unread message

Stevearc

unread,
Jul 18, 2013, 3:31:49 AM7/18/13
to salt-...@googlegroups.com
I occasionally found myself wanting to run some command like 'ls' or 'cat' or 'netstat' on a bunch of servers at once, but it was a bit annoying to do:

salt -G 'roles:webserver' cmd.run "cat /etc/myapp/some_config_file.yaml"

So I wrote a short little python script that makes salt's cmd.run module more interactive. If nothing else, it's fun to play with.

David Anderson

unread,
Jul 18, 2013, 11:42:19 AM7/18/13
to salt-...@googlegroups.com
Awesome! IMO, this should be an official tool included with salt.
salt-shell?
--
Dave

On 7/18/13 1:31 AM, Stevearc wrote:
> I occasionally found myself wanting to run some command like 'ls' or
> 'cat' or 'netstat' on a bunch of servers at once, but it was a bit
> annoying to do:
>
> salt -G 'roles:webserver' cmd.run "cat /etc/myapp/some_config_file.yaml"
>
> So I wrote a short little python script
> <https://gist.github.com/stevearc/6027355> that makes salt's cmd.run
> module more interactive. If nothing else, it's fun to play with.
> --
> 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.
>
>

Emile `iMil' Heitor

unread,
Jul 18, 2013, 11:58:23 AM7/18/13
to salt-...@googlegroups.com

> So I wrote a short little python script that makes salt's cmd.run module
> more interactive. If nothing else, it's fun to play with.

wow. This is absolutely great, thanks a lot for sharing! and yes, that
one should definitely be part of official saltstack :)

------------------------------------------------------------------
Emile `iMil' Heitor .�. <imil@{home.imil.net,NetBSD.org,gcu.info}>
_
| http://imil.net | ASCII ribbon campaign ( )
| http://www.NetBSD.org | - against HTML email X
| http://gcu.info | & vCards / \

Ethan Erchinger

unread,
Jul 18, 2013, 12:53:32 PM7/18/13
to salt-...@googlegroups.com
This is awesome, excellent work.

For those on Python2.6 (RHEL 6), change line 46 to this:
return lambda x: "\033[{0}m{1}\033[0m".format(termcode, x)

Steven Arcangeli

unread,
Jul 18, 2013, 1:13:04 PM7/18/13
to salt-users
Oh, good catch on the string formatting! I'll just update it to use the old %s style instead, since that should work across all python versions.


--
You received this message because you are subscribed to a topic in the Google Groups "Salt-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/salt-users/l8fhLrLw4xY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to salt-users+...@googlegroups.com.

Niels Abspoel

unread,
Jul 18, 2013, 2:58:03 PM7/18/13
to salt-...@googlegroups.com
This looks very nice, but how do I use it? is it a module that needs to go in /srv/salt/_modules?? 
Or do I just run it??

Op donderdag 18 juli 2013 09:31:49 UTC+2 schreef Stevearc het volgende:

Steven Arcangeli

unread,
Jul 18, 2013, 3:16:48 PM7/18/13
to salt-users
Just run it on your salt master. It hooks in and runs commands via salt.client.LocalClient


--

Tim O'Guin

unread,
Jul 18, 2013, 3:31:16 PM7/18/13
to salt-...@googlegroups.com
Nice. This is what I have in mind when I think about how I'd want to interact with salt-api on the command line. It'd be great to have this functionality combined with pepper[1] to serve as a general purpose shell for salt.



--
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.

David Boucha

unread,
Jul 18, 2013, 4:14:37 PM7/18/13
to salt users list
That's pretty cool!


--
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.
 
 



--
Dave Boucha  |  Sr. Engineer


5272 South College Drive, Suite 301 | Murray, UT 84123

office 801-305-3563
da...@saltstack.com | www.saltstack.com

Steve Butterworth

unread,
Jul 19, 2013, 10:01:07 AM7/19/13
to salt-...@googlegroups.com
Your script (omnishell.py) do_shell function depends on subprocess.check_output, which is available only in Python 2.7 .

See: Subprocess library .

You may want to support Python 2.6 and later since RedHat/CentOS 5  and 6 both have only Python 2.6 available via EPEL.

Reply all
Reply to author
Forward
0 new messages