# script module

**URL:** <https://forum.ansible.com/t/script-module/17688>\
**Category:** Ansible Project\
**Created:** [March 5, 2015, 11:32pm UTC](https://forum.ansible.com/t/script-module/17688 "2015-03-05T23:32:39Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Craig\_White](https://avatars.discourse-cdn.com/v4/letter/c/85e7bf/32.png) [@Craig\_White](https://forum.ansible.com/u/Craig_White)\
**Post date:** [March 5, 2015, 11:32pm UTC](https://forum.ansible.com/t/script-module/17688/1 "2015-03-05T23:32:39Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [March 6, 2015, 3:35am UTC](https://forum.ansible.com/t/script-module/17688/2 "2015-03-06T03:35:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Dag\_Wieers](https://avatars.discourse-cdn.com/v4/letter/d/45deac/32.png) [@Dag\_Wieers](https://forum.ansible.com/u/Dag_Wieers)\
**Post date:** [March 6, 2015, 9:46am UTC](https://forum.ansible.com/t/script-module/17688/3 "2015-03-06T09:46:53Z")

</div>

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 ?)

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [March 6, 2015, 9:49am UTC](https://forum.ansible.com/t/script-module/17688/4 "2015-03-06T09:49:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Craig\_White](https://avatars.discourse-cdn.com/v4/letter/c/85e7bf/32.png) [@Craig\_White](https://forum.ansible.com/u/Craig_White)\
**Post date:** [March 6, 2015, 5:47pm UTC](https://forum.ansible.com/t/script-module/17688/5 "2015-03-06T17:47:06Z")

</div>



---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [March 6, 2015, 6:00pm UTC](https://forum.ansible.com/t/script-module/17688/6 "2015-03-06T18:00:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [March 6, 2015, 6:25pm UTC](https://forum.ansible.com/t/script-module/17688/7 "2015-03-06T18:25:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [March 6, 2015, 6:29pm UTC](https://forum.ansible.com/t/script-module/17688/8 "2015-03-06T18:29:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dag\_Wieers](https://avatars.discourse-cdn.com/v4/letter/d/45deac/32.png) [@Dag\_Wieers](https://forum.ansible.com/u/Dag_Wieers)\
**Post date:** [March 6, 2015, 10:20pm UTC](https://forum.ansible.com/t/script-module/17688/9 "2015-03-06T22:20:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [March 6, 2015, 10:26pm UTC](https://forum.ansible.com/t/script-module/17688/10 "2015-03-06T22:26:47Z")

</div>

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