script module

Seems that the ‘script’ module wants a local file but I need the local file to be a template with variables ./templates/my_script.sh

Run script which removes the directory

  • name: perform OpenLDAP setup and clean up
    script: /tmp/slapd/add_ldifs.sh removes=/tmp/slapd

but this doesn’t work because /tmp/slapd/add_ldifs.sh is created from the template and exists on the remote and is not local. templates/add_ldifs.sh.j2 is local

Is there a way I can do this or do I just resort to running the shell script that I already have on the remote?

One way to do it is to create the template locally for the script
module, another would be to use the shell module instead to execute
the script.

It would be nice to have an action plugin for the script module that is activated when e.g. template=yes is added. And which would subsequently template the script.

(Or we could decide to always template when script is used ?)

​Given the extra processing and slow down that kicks in with templat​es,
I'd rather not.

given that I am a newbie, my opinions lack perspective. I think the
'script' command should be able to be gathered from a template because
ansible is just a glorified shell script manager anyway and why keep it
emasculated?

Yikes! I would in no way say that ansible is just a glorified shell script
manager. I do think you are lacking perspective

I can run the script that is derived from the template and dropped on the
subject server with the shell command - I thought the script
'creates/removes' functions added a bit of elegance that you don't get from
the shell module.

The shell and command modules also both utilize creates/removes

In my non-humble opinion, I think templating a shell script or any script
for that matter is pretty terrible.

I'd recommend tempting a config that the script can utilize to gather the
info it needs to perform a task, rather than building a script on the fly.
Or allowing the script to run off of ENV vars, and passing an "environment"
along with your command.

​I didn't say it should not be possible to template the script, just not by
default, as Dag suggested.​

​That could do terrible things yes :)​

​But I could see use cases. Instead of templating a separate config file,
just templating some variable declarations for example.

Either way, it's up to the user to write whatever's decent for his use case.

To be fair, I suggested three things. You selected one to comment on :slight_smile:

You can already use templates for script, either by running a local
template task or using the template lookup, I feel remiss to add
script generation from template to the module.

Not that I think dynamic shell generation should be done from ansible,
IMHO it is much cleaner to use shell/script with the environment:
keyword or simply passing the arguments in the command line (which can
use ansible variables).