script module

59 views
Skip to first unread message

Craig White

unread,
Mar 5, 2015, 6:32:39 PM3/5/15
to ansible...@googlegroups.com
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?

Brian Coca

unread,
Mar 5, 2015, 10:35:10 PM3/5/15
to ansible...@googlegroups.com
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.



--
Brian Coca

Dag Wieers

unread,
Mar 6, 2015, 4:47:09 AM3/6/15
to ansible...@googlegroups.com
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 ?)

--
Dag

Serge van Ginderachter

unread,
Mar 6, 2015, 4:50:21 AM3/6/15
to ansible...@googlegroups.com

On 6 March 2015 at 10:46, Dag Wieers <d...@wieers.com> wrote:
(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.

Craig White

unread,
Mar 6, 2015, 12:47:06 PM3/6/15
to ansible...@googlegroups.com
----
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?

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.

Thanks

Matt Martz

unread,
Mar 6, 2015, 1:01:01 PM3/6/15
to ansible...@googlegroups.com
On Fri, Mar 6, 2015 at 11:47 AM, Craig White <white...@gmail.com> wrote:
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.

--
Matt Martz
@sivel
sivel.net

Serge van Ginderachter

unread,
Mar 6, 2015, 1:26:17 PM3/6/15
to ansible...@googlegroups.com

On 6 March 2015 at 18:47, Craig White <white...@gmail.com> wrote:
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?


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

Serge van Ginderachter

unread,
Mar 6, 2015, 1:29:53 PM3/6/15
to ansible...@googlegroups.com
On 6 March 2015 at 19:00, Matt Martz <ma...@sivel.net> wrote:
In my non-humble opinion, I think templating a shell script or any script for that matter is pretty terrible.

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


Dag Wieers

unread,
Mar 6, 2015, 5:21:19 PM3/6/15
to ansible...@googlegroups.com
To be fair, I suggested three things. You selected one to comment on :)

--
Dag

Brian Coca

unread,
Mar 6, 2015, 5:26:56 PM3/6/15
to ansible...@googlegroups.com
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).
Reply all
Reply to author
Forward
0 new messages