Running script with arguments through ansible
<p>[Ansible version == 2.1.0]</p>

<p>In order to run a script which is present locally on the target server, we can use Ansible's "command" module. Following can be done easily:</p>

<pre><code>- name: Executing getpkgs.sh to download packages.
  command: sh "/path/to /dir/scriptName.sh" arg1 arg2 arg3 arg4
</code></pre>

<p>I have my script names and the arguments stored in ansible variables. For example, the following variable contains all the script names and the arguments to be passed to those scripts:</p>

<pre><code>scripts_to_execute:
  - { filename: "/path/to/file/file1.sh", args: "arg11 arg12 arg13"}
  - { filename: "/path/to/file/file2.sh", args: "arg21 arg22"}
  - { filename: "/path/to/file/file3.sh", args: "arg31 arg32 arg33 arg34"}
</code></pre>

<p>And i want all these files which are already present on the target server, to be executed using with_items. Trying to achieve something like the following:</p>

<pre><code>- name: Executing all files.
  command: sh "{{item.filename}}" "{{item.args}}"
  with_items: scripts_to_execute
</code></pre>

<p>I am trying to pass the script name followed by the string containing all arguments that are to be passed into the script. But it is considering that string of arguments as a single argument.</p>