Remote script module, 'script' for 0.9 (rough cut)

One of the things that occasionally comes up is you may want to run a
script on a remote server, and not have a module for it.

This practice is really not to be encouraged in some cases, but in
some cases, you're working with an external team or something doesn't
really make sense as a module, and it would be nice to save some time.

This is now possible in Ansible 0.9

script: /path/to/some/local_script some arguments --go-here

This will push the local script to a temp file on the remote machine
and execute it, returning data as if it was executed by the shell
module. (Unlike the command/shell module, creates= and removes= are
not yet supported, but I'd accept patches for those if people find
them useful).

This essentially eliminates a three step process in a playbook (and
more, in terms of internals):

(A) copy over a script
(B) execute the script with the command module
(C) delete the script

Check it out in the latest 0.9 code.

--Michael

This is now possible in Ansible 0.9

Damn! You beat me to it; I'd just started on that. (sigh). Oh, well,
your code will definitely be better than mine so thank you very much. :slight_smile:

        -JP

This is now possible in Ansible 0.9

Damn! You beat me to it; I'd just started on that. (sigh). Oh, well,
your code will definitely be better than mine so thank you very much. :slight_smile:

Yeah don't assume any of the kinks that need to be out of it are out of it.

Hello world, however, works.

Hi,
I tried to use the module “script” but it still require to have simpleJSON to be at remote hosts? Is there any other way to run shell script remotely beside using “raw” module? I am trying to put all my bash scripts in 1 server (ansible-master), and only run it remotely to all my hosts.

Thank you.

Even though creating a shell module is a piece of cake, I agree that having alternatives to shell and script that do not require python could be useful for those devices and cases lacking thel. Also improving raw to behave more like command is something I need myself.

It would make it also easier for Solaris/HPUX/AIX teams to start using Ansible by hooking existing scripts into Ansible, before migrating them over to Ansible playbooks/modules.

copy still requires simplejson, IIRC, due to various daisy chaining
requirements.

As much as it would be conceptually nice to iron it out, when we do,
we lose capabilities.

While it dilutes our 'no bootstrapping' case, I'd rather be able to
have things reasonably standardized.

The problem will fix itself in sufficient years of RHEL updates, and
the raw module isn't a *terrible* way to bootstrap the absense of
simplejson.

--Michael

Hi Michael,
I am using “raw”, but there are machines that can’t install additional software nor have python on them due to various reason (for example security policy and network devices), but is able to use ssh and shell/bash. That’s the reason why I am looking at the various other modules in ansible. “script” seem to be the 1 that would enable me to run shell script, but it require JSON, which kill my options.
Now, I will need to customize/re-write some of my current BASH/SHELL script in ansible module-like which can return JSON via echo/print. That will take some modification and time to test.
I will look into how “raw” module was written, and maybe can do something like what I am doing now:
$ ssh -l root localhost “cat localscript.sh

The above is how I am running my local script remotely, but I would prefer to have something more structural like ansible playbook/module.

Thank you.

Hi,
Have you start to improve “raw” module? I am also looking into having some module that don’t require python as my current environment is having network devices and some real “old and ancient” Unix that don’t like to be disturb (nor supported) with additional package.

Thank you.

Ok, I read the source again, there seems to be no reason why the
script module needs python because we are not using the 'copy' module
to transfer
the script.

I'm willing to consider patches that switch this from command to 'raw'
at the very bottom.

https://github.com/ansible/ansible/blob/devel/lib/ansible/runner/action_plugins/script.py

Should be trivial.

I am trying but seem like I really need to start learning python, as I got error when I just replace “command” with 'raw".

I haven't modified raw yet, and I may not get to it before my current contract wears out (in 5 days). The reason for improving raw is for Solaris and AIX (and I have none of these at home to test).

What I would like to change to raw is:

  - Return rc=
  - Return splitted stdout= and stderr=

The raw shell module could start the interpreter remotely and pipe the command directly into the interpreter (no need to transfer anything). It could be a single SSH round-trip. Also returning return code and stdout/stderr.

No python or python-json would be needed for any of the above, which would be great for appliances or OSes lacking those.

The raw shell module could be used with $FILE() for running scripts, although if script would not need python, that's even better :slight_smile:

PS We also have one issue where raw would stall indefinitely on some occasions, blocking everything (happens both on AIX and Solaris, never saw this on Linux). I still need to debug it...

Hmm, the point of raw is that is not a module and doesn't transfer
anything, so if it needs a place to store the module,
I am wondering if that limits utility on devices where it was talking
to a read only filesystem, or if that's even realistic?

It was originally requested by someone who was configuring network hardware.

Perhaps if a flag to raw was needed to switch it to the other behavior
or something.

BTW, ansible also has a 'python only' for modules in core policy --
this is for good reason, some of us are terrible with bash.

So, I think this is like 'raw2', and we can link to it on the docs page.

--Michael

But it would be python-only.

So the first changes to raw are provided through PR 1795:

     https://github.com/ansible/ansible/pull/1795

Since raw is using a shell by default, I don't think we need a separate 'rawshell' module though. But I plan to modify raw to change the interpreter (executable) like command/shell does.

Another item to fix is the banner/login output shown when using pseudo ttys. Either we should have a flag to disable pseudo tty's or we should be smart and filter out everything send (e.g. by piping the command through stdin and discarding everything in stdout/stderr before sending the command). Is that something we'd like to do ?

Without a fix for this, we would get the large banner in stdout for every command run. Compare output from DD-WRT.

Using quiet/pty (Ansible default):

     [dag@moria ansible]$ ssh -q -tt root@mist echo 'Test'

Looks good.

(A) agree we don't need a rawshell

(B) I think we were talking about modifying the 'script' module to
work more or less via 'raw', which is possibly the source of confusion
in (A).

(C) seeing this is all server side still, that is great... and we
don't need a raw2 either. Good deal.

I have PR 1799 ready for this, not sure if the implementation is acceptable and it may need some more testing from people actually using the script module.

     https://github.com/ansible/ansible/pull/1799

This is now possible too with PR 1798:

     https://github.com/ansible/ansible/pull/1798

Feedback and testing welcome !

Thanks guys. I will tryout the “script” and “raw” module from https://github.com/ansible/ansible/pull/1799.

Tested “script” module, and it seem like missing the 'newline" problem as in “raw” module, which is not fixed in https://github.com/ansible/ansible/pull/1795.

Thank you.