<p>Append the parameters after the command. See the example below.</p>

<pre><code># ansible -m shell --args "pwd; touch test; ls -1 chdir=/scratch/tmp creates=/scratch/tmp/test" localhost
localhost | CHANGED | rc=0 &gt;&gt;
/scratch/tmp
test

# ansible -m shell --args "pwd; touch test; ls -1 chdir=/scratch/tmp creates=/scratch/tmp/test" localhost
localhost | SUCCESS | rc=0 &gt;&gt;
skipped, since /scratch/tmp/test exists
</code></pre>

CC BY-SA 4.0
2019-04-26T08:48:54.820Z
2019-05-04T11:57:03.880Z
2019-05-04T11:57:03.880Z
Vladimir Botka
<p>Is it possible to pass <code>args</code>, to the shell module when running it as an adhoc command?</p>

<p>I can pass the <code>free_form</code> parameter using <code>-a</code>, but I am trying to figure out how to specify additional arguments, such as <code>chdir</code> or <code>executable</code>.</p>

<p>For example, what is the adhoc equivalent to this task?</p>

<pre><code>- name: Change working dir to somedir/ and run somescript.sh using bash
  shell: somescript.sh &gt;&gt; somelog.txt
  args:
    chdir: somedir/
    executable: /bin/bash
</code></pre>

<ansible>
passing args to shell module in Ansible adhoc command
thinkmassive
# passing args to shell module in Ansible adhoc command

(Asked by: username_0 on 2019-04-25)

Is it possible to pass args, to the shell module when running it as an adhoc command?
I can pass the free_form parameter using -a, but I am trying to figure out how to specify additional arguments, such as chdir or executable.
For example, what is the adhoc equivalent to this task?
- name: Change working dir to somedir/ and run somescript.sh using bash
  shell: somescript.sh >> somelog.txt
  args:
    chdir: somedir/
    executable: /bin/bash

**Tags:** ansible


---

## 1 answers

### Answer by username_1 on 2019-04-26. Score: 8 | Accepted answer

Append the parameters after the command. See the example below.
# ansible -m shell --args "pwd; touch test; ls -1 chdir=/scratch/tmp creates=/scratch/tmp/test" localhost
localhost | CHANGED | rc=0 >>
/scratch/tmp
test

# ansible -m shell --args "pwd; touch test; ls -1 chdir=/scratch/tmp creates=/scratch/tmp/test" localhost
localhost | SUCCESS | rc=0 >>
skipped, since /scratch/tmp/test exists


---

