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