Understanding the script module

Hello, all.

We have an occasional need to update a particular piece of a core business application across a number of Windows servers. The process involves a number of steps, most done via the application UI. It’s tedious and time consuming so, of course, I’ve created a python script to do the actual update (fortunately, the update process can be done from the command line, albeit via a number of steps), and a playbook to execute it. Here’s the playbook:


  • hosts: all
    gather_facts: false
    any_errors_fatal: true
    tasks:
  • name: reload DAO
    local_action: script /etc/ansible/files/DAO_update.py {{ inventory_hostname }}
    register: dao_output
  • debug: var=dao_output.stdout_lines

Note the use of local_action. When I tried to simply use the script module (script: /etc/ansible/files/DAO_update.py {{ inventory_hostname }}), I got no errors, but the script didn’t execute. I determined this by running tcpdump, which returned no output. If I ran the script manually, tcpdump returned expected output. However, If I ran the playbook with local_action (as above), tcpdump returned the expected output; e.g. the script executed properly. Why did using the script module not work? According to the script module documentation, among other things, python isn’t required to be installed on the target. An explanation would be appreciated.

The first line in the documentation is
"script - Runs a local script on a remote node after transferring it"

So the script module copy the script from ansible controller to the _remote_ and execute the script on _remote_ host.

The script module doesn't require python installed, but if you are running a Python script on the remote host of course you need Python on the remote host.

So if you are intending to execute this script on the Ansible controller, use the command module and "local_action/delegate_to: localhost" or just set the "connection: local" in the playbook with the command module.

Thanks, Kai. So, am i misinterpreting this line from the documentation?:

  • This module does not require python on the remote system, much like the raw module.
    That seems to mean (to me, at least) just what is says, that there’s no need for python to be installed on the Windows systems in which the script is being executed.

Yes for the module script it self, Python is not required.

But if you copy over a Python script to the Windows system and execute it you must have Python installed.
Ansible is not magic, it can execute something on remote system that is doesn't support.

You use script with a Powershell script, but you still need Powershell installed on the Windows machine to execute it.

So the script module only copy the script over(does not require Python) and start the script(does not require Python), but the remote system must support the language you wrote the script with.

If the script you wrote is Powershell, you need Powershell install on remote, but the remote don't need Python to use the script module.

OK, and thanks, as always for your input/insight. I figured that when I first used the script module, and it “failed”. That’s when I turned to local_action. Still, I think that the documentation could be a bit more clear.